mov
Move
Copies the contents of the source (second) operand into the destination (first) operand.
8086 and later
- Getting started with x86-64x86-64 assembly
- The 16 registers and their halvesx86-64 assembly
- Memory, little endian and sizesx86-64 assembly
- Bytes, words, dwords and qwordsx86-64 assembly
- The x86-64 instruction setx86-64 assembly
- Effective addressesx86-64 assembly
- The flags registerx86-64 assembly
- Sections, directives and labelsx86-64 assembly
- Memory regions and executable filesx86-64 assembly
- cmp and the conditional jumpsx86-64 assembly
- 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
raxorqword [rbp-8]. reg- A general-purpose register matching the operation’s size, for example
al,ax,eaxorrax. imm- An immediate value: a constant written in the instruction as a number, a character or a label, for example
10,0x1f,'a'ormsg. Open a row to see the size it has in each form, such asimm8orimm32. mem16- A 16-bit value in memory, for example
word [rbx+8]. segreg- A segment register:
es,cs,ss,ds,fsorgs. acc- The accumulator:
al,ax,eaxorrax, 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 bymovto transfer data to or from the accumulator. reg64- A 64-bit general-purpose register:
rax,rbx,rcx,rdx,rsi,rdi,rsp,rbporr8tor15. creg- A control register, such as
cr0,cr2,cr3,cr4orcr8. An operating system uses these registers to configure the processor. dreg- A debug register,
dr0todr7. 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