Quiz Entry - updated: 2026.07.14
What are the exact effects of PUSH and POP instructions in x86-64?
pushq first subtracts 8 from %rsp, then writes; popq first reads, then adds 8 to %rsp — exactly because the stack grows downward.
The order of the two steps is what people get wrong, so it's worth memorizing precisely:
| Instruction | Effect |
|---|---|
pushq S |
%rsp ← %rsp − 8; then M[%rsp] ← S |
popq D |
D ← M[%rsp]; then %rsp ← %rsp + 8 |
Each is exactly equivalent to a pair of plain instructions, which is the clearest way to see what's happening:
# push %rax ==
subq $8, %rsp
movq %rax, (%rsp)
# pop %rbx ==
movq (%rsp), %rbx
addq $8, %rsp
Note: size modifiers exist (push[b,w,l,q], pop[b,w,l,q]), but in 64-bit code pushq/popq are overwhelmingly the common forms, since the stack works in 8-byte units. Good practice is to keep pushes and pops balanced and in reverse order (push a, b, c → pop c, b, a).
Go deeper:
Felix Cloutier — PUSH — PUSH's decrement-then-store order.
Felix Cloutier — POP — POP's read-then-increment order.