PUSH
By Vesper Vei
2 minutes read
Table of Contents
PUSH (push)
Basic purpose
The PUSH instruction pushes an operand onto the stack and updates the stack pointer.
In x86/x64, the stack grows toward lower addresses, so PUSH decreases the value of ESP/RSP first, then writes the data to the new top of the stack.
Instruction execution process
Using 64-bit as an example:
rsp = rsp - 8[rsp] = 操作数For 32-bit:
esp = esp - 4[esp] = 操作数Instruction format
The following operands are allowed:
- push r/m16
- push r/m32
- push r/m64
- push imm8 / imm16 / imm32 (in x64, it is sign-extended to 64 bits)
The sign extension of immediate pushes is a unique behavior of PUSH.
Behavioral characteristics
- The stack pointer moves downward
- Writing a value does not clear old memory; it only overwrites it
- Immediate values are sign-extended (
push imm32→ 64bit) - Operands cannot be two memory addresses
- The stack layout changes, affecting function call offset calculations
Equivalent expansion example
push rax; 等价于sub rsp, 8mov [rsp], raxpush 0x1234sub rsp, 8mov qword ptr [rsp], 0x0000000000001234ASCII stack change illustration
Before execution:
rsp → +------------------+ | (旧栈数据) | +------------------+After executing push rax:
+------------------+rsp → | rax 的值 | +------------------+ | (旧栈数据) |
Common uses
- Save register contents
- Push arguments during function calls
- Align stack space
- Temporarily save data
- In PWN, used to control stack layout and overwrite return addresses