# `push`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/push

**Push value onto the stack**

Category: 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](https://intel.github.io/SDM/instruction/PUSH.html)

Used in: [The stack, push and pop](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/the-stack-push-and-pop.md) (x86-64 assembly), [call, ret and the System V convention](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/call-ret-and-the-system-v-convention.md) (x86-64 assembly), [Stack arguments and a stack frame](https://asm-editor.specy.app/learn/courses/x86/examples/subroutine-with-stack-arguments.md) (x86-64 assembly), [Recursion: factorial and Fibonacci](https://asm-editor.specy.app/learn/courses/x86/examples/factorial-and-fibonacci.md) (x86-64 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| CF | not changed |
| PF | not changed |
| AF | not changed |
| ZF | not changed |
| SF | not changed |
| DF | not changed |
| OF | not changed |

## Forms

- `push reg` (16, 64)
  - `push reg16`
  - `push reg64`
- `push r/m` (16, 64)
  - `push r/m16`
  - `push r/m64`
- `push imm` (8, 16, 32)
  - `push imm8`: 186 and later
  - `push imm16`: 186 and later
  - `push imm32`: 386 and later
- `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`.
- `r/m`: A general-purpose register or memory location matching the operation’s size, for example `rax` or `qword [rbp-8]`.
- `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.

## Description

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.

## Example

```x86
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
```
