I need to increment a number so that the code will increment forever, but it stays zero.
Here is my code:
section .data
FORMAT: db '%c', 0
FORMATDBG: db '%d', 10, 0
EQUAL: db "is equal", 10, 0
repeat:
push ecx ; just to print
push FORMATDBG ; just to print
call printf ; just to print
add esp, 8 ; add the spaces
inc ecx ; increment ecx
cmp ecx, 0 ; compare ecx to zero
ja repeat ; if not equal to zero loop again
xor ecx, ecxsetsecxto zero. I’m not sure if you know this. You probably do not want it to happen on each iteration. Furthermore your loop conditionja repeatcurrently causes a loop only ifecx > 0which is probably not what you wanted (or is it?).One last thing,
printfprobably trashesecx(I am assumingcdeclorstdcall). Read up on call conventions (not sure what compiler/OS you are on) and see which registers are guaranteed to be preserved in function calls.In terms of your code, you probably wanted something closer to this:
This will not cause an infinite loop though. When
ebxreaches its maximum value, its value will wrap around back to 0 which will cause the loop condition (ebx>0) to evaluate to false and your loop to be exited.