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

Intel's reference: PUSH

CFPFAFZFSFDFOF –––––––
  • Changes no flag

Forms

  • push fs 386 and later
  • push gs 386 and later

Operands

reg
A general-purpose register matching the operation’s size, for example al, ax, eax or rax. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, which is required by spl, bpl, sil, dil and r8–r15.
r/m
A general-purpose register or memory location matching the operation’s size, for example rax or qword [rbp-8]. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, including when the memory address uses r8–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 word for 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