Search code examples
assemblyx86gnu-assembler

Assembly infinite loop


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.