C++
ATT Assembly
I'm trying to understand the behavior of the following two instructions:
pushl %esp
And:
popl %esp
Note that they store the computed value back into %esp
.
I'm considering these instructions independently, not in sequence. I know that the value stored in %esp
is always the value before the increment/decrement, but how could I represent the behavior in assembly language? This is what I've come up with so far:
For push:
movl %esp, %edx 1. save value of %esp
subl $4, %esp 2. decrement stack pointer
movl %edx, (%esp) 3. store old value of %esp on top of stack
For pop:
movl (%esp), %esp You wouldn’t need the increment portion.
Is this correct? If not, where am I going wrong? Thanks.