previous | start | next

IA32 ret Instruction

The ret instruction removes the top value of the stack and stores it in register %eip. That's all!

So before executing the ret instruction, f must prepare the stack so that the stack pointer is changed so that the top of the stack contains the instruction return address in main's code.

This preparation can be done with two instructions:

      movl %ebp, %esp ; make %esp point to the bottom of f's frame
      popl %ebp       ; reset frame pointer %ebp to point to bottom of main's frame
   

The popl instruction copies the top of the stack into %ebp, but also increments the stack pointer %esp.

Now the return address is uncovered and is at the top of the stack. So the ret instruction can do its work.



previous | start | next