LOGBOOK

HELP

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, cpop c, b, a).

Go deeper:

From Quiz: REVE1 / The Processor Interface | Updated: Jul 14, 2026