Question
My saga with x86 assembly continues, I'm getting into an infinite loop with this piece of code and I'm a bit puzzled.
movl $1, %ecx
movl $4, %edi
do_loop:
cmpl %edi, %ecx
je do_exit
.........
do_stuff
.........
incl %ecx
jmp do_loop
do_exit:
I'm expecting a jump to do_exit: when %ecx reaches 4 since it's incremented in every iteration
Solution
As others have mentioned, be careful with register usage in do_stuff
. And the real thing that you are looking for are calling conventions, and especially this line:
Registers EAX, ECX, and EDX are available for use in the function.
OTHER TIPS
No debugger? Does do_stuff modify %edi? Try commenting do_stuff out.
I dont know if the do_exit is followed by blanks and I have no idea how you are executing the assembly code...
but try to add the following after the do_exit:
leave
ret
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow