I recently tried out a simple loop test. I followed the instruction manual. Although, mnemonics is somewhat true but all I get is an infinite loop result.
Here's my code:
.code
start:
mov eax,0
call main
exit
main proc
mov eax,sval(input("Enter a number: "))
mov ecx,0
.while eax > 0
print str$(ecx)
print chr$(13,10)
sub eax,1
add ecx,1
.endw
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; Equal or similar to while syntax
; returnHere:
; print str$(ecx)
; print chr$(13,10)
; add ecx,1
; cmp eax,0
; sub eax,1
; ja returnHere
;
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
ret
main endp
end start
After compiling and running it. I get an infinite loop.
Enter a number: 2
.
.
.
2088832679
2088832679
2088832679
2088832679
.
.
.
What I want is suppose to be like this.
Enter a number: 2
0
1
2
I'm running out of idea how to work this out. Need help... :P
try this.
.while SDWORD PTR eax > 0
The current code is unsigned, this makes it signed.
eax, ecx, edx are trash registers - they will be modified by print and str$
ebx, esi, edi are reserved registers - they will not be modified. It's called Windows ABI (http://www.google.it/search?num=50&hl=en&newwindow=1&safe=off&client=firefox-a&rls=org.mozilla%3Aen-GB%3Aofficial&hs=jfm&q=Windows+%22application+binary+interface%22&btnG=Search)
push ebx ; save
mov ebx, 123
.while ebx > 0
print str$(ecx)
print chr$(13,10)
sub ebx,1
add ecx,1
.endw
pop ebx
Give this a blast.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
call main
inkey
exit
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
push ebx
push esi
mov ebx, sval(input("Enter a number: "))
xor esi, esi ; set ESI to zero
.while SDWORD PTR ebx >= 0
print str$(esi),13,10
sub ebx,1
add esi,1
.endw
pop esi
pop ebx
ret
main endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end start
LATER: I just cirrected an error, had the ESI EBX registers popped in the wrong order.
Thanks hutch-- and jj2007. I got them noted. :U
Regards,
eaOn