Search code examples
assemblynasm

Assembly CALL and RET stack


I have question.When I know that

call <address>

is equivalent to

push rip  
jmp <address>

and I also know that

ret

is equivalent to

pop rip
jmp <rip>

But if we jump to rip why don’t we start this loop again because we push rip before jump and rip specify on jump? Can you explain how do we pass this jump in code


Solution

  • Various processors have different ways of handling this. On some, the call pushes the address of the instruction after the call. On others, the ret adds the length of the call instruction to the return address before jumping.

    The first method is more flexible because it makes it possible to use various addressing modes with different instruction lengths in the call. It's also likely that the instruction decoder already knows the location of the next instruction as the call is being processed.