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

Intel's reference: POP

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

Forms

  • pop fs 386 and later
  • pop 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.

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