POP
By Vesper Vei
2 minutes read
Table of Contents
POP(pop)
Basic Function
The POP instruction pops the top value from the stack into the destination operand, then moves the stack pointer upward.
In contrast to PUSH, POP increases ESP/RSP.
Instruction Execution Process
64-bit:
操作数 = [rsp]rsp = rsp + 832-bit:
操作数 = [esp]esp = esp + 4Instruction Format
The following operands are allowed:
- pop r/m16
- pop r/m32
- pop r/m64
Not allowed:
- pop memory to memory
- pop immediate
Behavioral Characteristics
- The stack pointer moves upward
- The original stack data is not cleared; it only becomes logically invalid
- POP cannot directly pop an immediate value
- The destination register size must match when popping into a register (
pop rax→ 8 bytes)
Equivalent Expansion Example
pop rax; 等价于mov rax, [rsp]add rsp, 8ASCII Stack Diagram
Before execution:
rsp → +------------------+ | 要弹出的值 | +------------------+After executing pop rax:
rsp → +------------------+ | (旧数据) | +------------------+; rax = 原栈顶值
⚠️ Note: the stack data at 0x0012FF88 here will not be cleared, but it will be overwritten during normal program execution
Common Uses
- Restore saved registers
- Restore stack state before a function returns
- Move the top of the stack to skip data
- Used in PWN for stack pivoting or stack adjustment