[ACCEPTED]-Why does leave do "mov esp,ebp" in x86 assembly?-x86

Accepted answer
Score: 93

mov esp,ebp sets the stack pointer to the base frame 7 address, effectively releasing the whole 6 frame. (Don't forget that this is Intel 5 syntax, the destination comes first.) If 4 you didn't do it, once you call ret, you would 3 still be using the called function's stack 2 frame with your calling function, with crashtastic 1 consequences.

Score: 4

I think your issue is the fact that there 9 are two different ways of writing x86 assembly. One 8 is the AT&T notation and the other is 7 the Intel notation. The order of the arguments 6 to an instruction are reversed in Intel 5 notation as opposed to AT&T. Your version 4 of the assembly appears to be in Intel notation, which 3 means that mov esp, ebp actaully moves the value in 2 ebp to esp. In the more logical (in my opinion) AT&T 1 notation it would be mov %ebp, %esp.

Score: 2

The compiler use this instruction to free 3 the used space by the function in the stack, the 2 leave instruction has the same behavior as mov esp, ebp with 1 pop ebp.

More Related questions