pop
Pop a value from the stack
Pops a 64-bit value using rsp by default, or a 16-bit value when a word operand is selected.
8086 and later
Used in
- 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
CFPFAFZFSFDFOF –––––––
- Changes no flag
Forms
pop fs386 and laterpop 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.
A 16-bit operand pops two bytes instead: pop ax adds 2. There is no 32-bit general-purpose pop in 64-bit mode, so pop eax is invalid. Popping into rsp replaces it with the loaded value.
An address-size prefix changes an explicit memory destination's addressing, not the stack pointer used to read the value. For a memory destination based on rsp, the destination address is calculated after the stack increment. Only fs and gs segment pops are available in 64-bit mode; loading them is subject to segment-selector checks.
global _start
section .text
_start:
mov rax, 12
push rax
mov rax, 99
pop rax ; 12 again
mov rax, 60 ; syscall 60: exit
xor rdi, rdi
syscall