Instructions
x86-64PUSH / POP
Pushes a value onto the stack (decrements RSP, then writes) or pops one off (reads, then increments RSP).
PUSH and POP are the primary instructions for manipulating the call stack.
In 64-bit mode the default operand size is 64 bits (8 bytes).
Operation
push rax ; RSP -= 8 ; [RSP] = rax
pop rbx ; rbx = [RSP] ; RSP += 8
push 0x1234 ; immediate push — sign-extended to 64 bitsPUSH first decrements RSP by the operand size, then writes the value.
POP first reads the value at [RSP], then increments RSP.
Neither instruction modifies EFLAGS (except POPF/POPFD/POPFQ, which
restore flags from the stack).
Function prologue/epilogue pattern
; Prologue — save callee-saved registers
push rbp
mov rbp, rsp
push rbx
push r12
; ... body ...
; Epilogue — restore in reverse order
pop r12
pop rbx
pop rbp
retThe push rbp / mov rbp, rsp pair creates a stack frame that debuggers and
unwinders use to walk the call chain.
Reverse-engineering notes
- A string of
pushinstructions at the start of a function usually saves callee-saved registers; the matchingpops at the end are the epilogue. - Some compilers replace
push regwithsub rsp, 8/mov [rsp], reg— functionally identical but slightly larger code; common with-O2. push immis a compact way to pass a constant argument on the stack (32-bit sign-extended) when stack-based argument passing is needed.- Spotting mismatched push/pop counts is an easy way to identify stack-cleanup bugs or intentional obfuscation.
Try it — Virtual CPU
open full playground →- 1 mov rax, 0x1111
- 2 mov rbx, 0x2222
- 3 push rax
- 4 push rbx
- 5 pop rcx
- 6 pop rdx
- 7
step 0
▸ Loading emulator…