Decribing pop in Assembly
assembly, cpu-registers, x86
Solution
Here's a small portion of the pseudo code for the POP instruction from Intel's documentation:
IF StackAddrSize = 32
THEN
IF OperandSize = 32
THEN
DEST ← SS:ESP; (* Copy a doubleword *)
ESP ← ESP + 4;
ELSE (* OperandSize = 16*)
...
FI;
...
But here's what it says specifically about `POP xSP`:
The POP ESP instruction increments the stack pointer (ESP) before data at the old top of stack is written into the destination.
This means that the sequence
PUSH ESP
POP ESP
does nothing out of ordinary, just like this one:
PUSH EAX
POP EAX
Similarly, there's some text on `PUSH xSP`:
The PUSH ESP instruction pushes the value of the ESP register as it existed before the instruction was executed. If a PUSH instruction uses a memory operand in which the ESP register is used for computing the operand address, the address of the operand is computed before the ESP register is decremented.
Problem
I am studying up on IA32. When I think about what the `popl DEST` instruction is doing I think the following: ``` movl (%esp), DEST addl $4, %esp ``` But then I started second guessing myself when I thought about `popl %esp`. Even though that is probably a pointless instruction, I think there is probably a better way to think of generally describing the `popl DEST` instruction. How would you describe it?