It's said that the leave instruction is the same as :
mov esp,ebp
pop ebp
But what is mov esp,ebp here for? It doesn't seem valid to me...
It's said that the leave instruction is the same as :
mov esp,ebp
pop ebp
But what is mov esp,ebp here for? It doesn't seem valid to me...
mov esp,ebp sets the stack pointer to the base frame address, effectively releasing the whole frame. (Don't forget that this is Intel syntax, the destination comes first.) If you didn't do it, once you call ret, you would still be using the called function's stack frame with your calling function, with crashtastic consequences.
mov esp,ebp set the base pointer to the stack pointer's address? mov ebp,esp would update the stack pointer to point at the base frame.
– DIMMSum
Jun 10 '15 at 18:37
%, we're talking about Intel-style, where destination comes first. The equivalent AT&T-style disassembly for this question, which you are probably thinking of and where destination comes last, would be movl %ebp, %esp.
– zneak
Jun 10 '15 at 20:11
I think your issue is the fact that there are two different ways of writing x86 assembly. One is the AT&T notation and the other is the Intel notation. The order of the arguments to an instruction are reversed in Intel notation as opposed to AT&T. Your version of the assembly appears to be in Intel notation, which means that mov esp, ebp actaully moves the value in ebp to esp. In the more logical (in my opinion) AT&T notation it would be mov %ebp, %esp.
move ebp into esp. The "Intel" notation (which predates Intel by a loooooooooooong time -- for example the Interdata 16-bit series which dates back to the '60s uses exactly this format and was by no means the first...) has semantics more like move such that esp = ebp.
– JUST MY correct OPINION
Mar 29 '11 at 16:15
movd is actually an MMX instruction. If you wanted to include a size suffix (which in this case is optional, mind you) you'd use movl
– bug
Oct 16 '12 at 3:42
esp = ebp
– phuclv
Aug 12 '13 at 9:15
The compiler use this instruction to free the used space by the function in the stack, the leave instruction has the same behavior as mov esp, ebp with pop ebp.
enter and leave cannot both be for the purpose of freeing the used space on the stack?
– Pascal Cuoq
Oct 31 '14 at 10:47