Quiz Entry - updated: 2026.07.14
What do push and pop actually do internally?
push subtracts 8 from %rsp then writes the value there; pop reads from %rsp then adds 8 back.
* push = rsp minus 8 then store; pop = load then rsp plus 8, because the stack grows toward lower addresses. *
push %rbx
is equivalent to:
sub $8, %rsp
mov %rbx, (%rsp)
pop %rbx
is equivalent to:
mov (%rsp), %rbx
add $8, %rsp
Key detail: The stack grows downward (toward lower addresses). So push subtracts and pop adds.
On x86_64, push/pop always move 8 bytes. On 32-bit x86, they move 4 bytes.
Go deeper:
PUSH instruction reference — confirms PUSH decrements the stack pointer then stores the operand at the top of the stack.
Call stack (Wikipedia) — how push/pop build the call stack and why growth direction is architecture-dependent.
Stack frame layout on x86-64 (Eli Bendersky) — shows where pushed values sit relative to rsp within a real frame.