Why leave "mov esp, ebp" in x86 assembly?

He said the leave command is the same as:

 mov esp,ebp pop ebp 

But why is mov esp,ebp ? It doesn't seem to me ...

+61
assembly x86
Mar 29 2018-11-11T00:
source share
3 answers

mov esp,ebp sets the stack pointer to the address of the base frame, effectively freeing the entire frame. (Donโ€™t forget that this is Intel syntax, the destination comes first.) If you havenโ€™t done this as soon as you call ret , you will still use the call stack stack frame with your calling function with short-term consequences.

+87
Mar 29 '11 at 2:48
source share

I think your problem is that there are two different ways to write an x86 assembly. One is AT&T notation, and the other is Intel notation. The order of arguments for the command is canceled in Intel notation, unlike AT & T. Your assembly version is displayed in Intel notation, which means that mov esp, ebp actaully moves the value in ebp to esp . In a more logical (in my opinion) AT & T notation would be mov %ebp, %esp .

+4
Mar 29 '11 at 2:47 a.m.
source share

The compiler uses this instruction to free the used space by the function on the stack, the leave statement has the same behavior as mov esp, ebp with pop ebp .

+1
Aug 12 '13 at 8:57
source share



All Articles