mov

Move

Copies the contents of the source (second) operand into the destination (first) operand.

8086 and later

Intel's reference: MOV

CFPFAFZFSFDFOF –––––––
  • Leaves every flag unchanged

Forms

  • mov ,
  • mov ,

Privileged

These forms require kernel mode, the mode an operating system runs in. A program in the editor runs in user mode, as any Linux program does, so running one of them ends the program with a signal.

  • mov ,
  • mov ,
  • mov ,
  • mov ,

Operands

r/m
A general-purpose register or memory location matching the operation’s size, for example rax or qword [rbp-8].
reg
A general-purpose register matching the operation’s size, for example al, ax, eax or rax.
imm
An immediate value: a constant written in the instruction as a number, a character or a label, for example 10, 0x1f, 'a' or msg. Open a row to see the size it has in each form, such as imm8 or imm32.
mem16
A 16-bit value in memory, for example word [rbx+8].
segreg
A segment register: es, cs, ss, ds, fs or gs.
acc
The accumulator: al, ax, eax or rax, whichever matches the operation’s size. The form accepts no other register in this position.
moffs
An absolute memory address with no base or index register, such as [label], used by mov to transfer data to or from the accumulator.
reg64
A 64-bit general-purpose register: rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp or r8 to r15.
creg
A control register, such as cr0, cr2, cr3, cr4 or cr8. An operating system uses these registers to configure the processor.
dreg
A debug register, dr0 to dr7. An operating system uses them to set hardware breakpoints for a debugger.

Register and memory data normally have the same width, and at most one operand can be memory.

Writing a 32-bit register clears the upper 32 bits of its 64-bit register: mov eax, -1 leaves rax = 0x00000000ffffffff. Writing ax or al preserves the remaining bits of rax.

A register-immediate move can load all 64 bits: mov rax, 0x123456789abcdef0 needs no special mnemonic. NASM chooses a shorter encoding when the same value can be obtained by a 32-bit register write or a sign-extended 32-bit immediate. For example, mov rax, 1 can use the former, while mov rax, -1 can use the latter. mov rax, strict qword 1 forces the full 64-bit immediate field.

A move of an immediate directly into 64-bit memory has only a 32-bit immediate field, sign-extended to 64 bits. Thus mov qword [rdi], -1 stores eight bytes of ones. To store an arbitrary 64-bit constant, first load it into a register, then store that register. A memory size such as qword specifies the stored width, not an immediate field of that width.

The accumulator memory-offset forms use al, ax, eax or rax and an absolute memory address; the address width and the data width are separate. CS cannot be a destination.

global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        mov rax, rbx

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall