X86 assembly - leave instruction

He said the leave instruction is like:

movl %ebp, %esp popl %ebp 

I understand the movl %ebp, %esp and that it acts to free the stored memory (as discussed in this question ).

But what is the purpose of the popl %ebp code?

+6
source share
1 answer

LEAVE is an analogue of ENTER . The ENTER instruction sets the stack stack by first pushing EBP the stack and then copying the ESP to EBP , so LEAVE must do the opposite, i.e. copy EBP to ESP and then restore the old EBP from the stack.

See “PROCEDURAL CALLS FOR BLOCK STRUCTURAL LANGUAGES” in Intel Developer's Guide for Developers Volume 1, if you want to learn more about how ENTER and LEAVE .

+13
source

Source: https://habr.com/ru/post/985650/


All Articles