Why does pop accept a parameter in the assembly?

popl %ebp 

It seems that %ebp not needed because the pop stack operation does not need a parameter.

Why does that make sense?

+7
assembly stack x86 callstack arguments pop
source share
3 answers

From http://www.cs.virginia.edu/~evans/cs216/guides/x86.html

pop - Pop stack

A pop command deletes a 4-byte data item from the top of the stack supported by the device to the specified operand (i.e., register or memory location). First, it moves 4 bytes located in the [SP] memory location to the specified register or memory location, and then increases the SP by 4.

Syntax
pop <reg32>
pop <mem>

Examples
pop edi - put the top element of the stack in EDI.
pop [ebx] - put the top element of the stack into memory in four bytes, starting at the EBX location.

Another good recommendation is http://en.wikibooks.org/wiki/X86_Assembly , and it is available in a PDF form .

+9
source share

this parameter sets the destination.

+6
source share

In order to expand the answer of Andrei, in addition to increasing the stack pointer on the popped element, the popped element is also copied to the destination address or register.

The instruction you gave is more or less equivalent to the two instructions (Intel syntax)

 add esp, 4 # increment the stack pointer mov ebp, [esp - 4] # load what ESP was pointing to 

I think this is in the syntax of att (gas)

 add $4, %esp mov -4(%esp), %ebp 

Of course, pop does not change the flags (so imagine that you are doing add with LEA), and this is not interrupted between loading and adding.

For the pop esp special case, executing the second load in pseudo-code repeats the actual documented behavior of the increment before the data from the old stack top location is written to ESP. And doing the increment before calculating the address for the destination pop memory, using %esp as part of the addressing mode, like popl 12(%esp, %edx, 4)

+4
source share

All Articles