push
Push value onto the stack
Pushes a 64-bit value using rsp by default, or a 16-bit value when a word operand is selected.
8086 and later
- The stack, push and popx86-64 assembly
- call, ret and the System V conventionx86-64 assembly
- Stack arguments and a stack framex86-64 assembly
- Recursion: factorial and Fibonaccix86-64 assembly
- Changes no flag
Forms
push fs386 and laterpush gs386 and later
Operands
reg- A general-purpose register matching the operation’s size, for example
al,ax,eaxorrax. The byte registersah,bh,chanddhcannot be used with a REX prefix, which is required byspl,bpl,sil,dilandr8–r15. r/m- A general-purpose register or memory location matching the operation’s size, for example
raxorqword [rbp-8]. The byte registersah,bh,chanddhcannot be used with a REX prefix, including when the memory address usesr8–r15. imm- A value to push. A default 64-bit push encodes a signed 8-bit or 32-bit immediate and sign-extends it to 64 bits. Use
wordfor a 16-bit push. A full 64-bit immediate cannot be encoded.
For example, push rax saves eight bytes. A 16-bit operand is also available: push ax subtracts 2 and stores two bytes. There is no 32-bit general-purpose push in 64-bit mode: push eax is invalid.
An immediate field can be smaller than the stack value. The default 64-bit push sign-extends an 8-bit or 32-bit immediate to 64 bits: push -1 stores eight bytes of ones. NASM chooses the short encoding when possible; push strict qword 1 keeps the 32-bit immediate field while still pushing eight bytes. push word 1 instead pushes two bytes. No push encodes a full 64-bit immediate; load an arbitrary 64-bit constant into a register, then push it.
The stack pointer remains rsp in 64-bit mode. An address-size prefix changes how an explicit memory source is addressed, not which stack pointer the push uses. Only fs and gs segment pushes are available in this mode; push cs, push ds, push es and push ss are unavailable.
global _start
section .text
_start:
mov rax, 12
push rax ; rsp moves down by 8
mov rax, 99
pop rax ; and back up, with 12 in rax again
mov rax, 60 ; syscall 60: exit
xor rdi, rdi
syscall