# `mov`

[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/mov

**Move**

Category: Data movement

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

8086 and later

[Intel's reference: MOV](https://intel.github.io/SDM/instruction/MOV.html)

Used in: [Getting started with x86-64](https://asm-editor.specy.app/learn/courses/x86/introduction/getting-started.md) (x86-64 assembly), [The 16 registers and their halves](https://asm-editor.specy.app/learn/courses/x86/introduction/the-16-registers-and-their-halves.md) (x86-64 assembly), [Memory, little endian and sizes](https://asm-editor.specy.app/learn/courses/x86/introduction/memory-little-endian-and-sizes.md) (x86-64 assembly), [Bytes, words, dwords and qwords](https://asm-editor.specy.app/learn/courses/x86/introduction/bytes-words-dwords-and-qwords.md) (x86-64 assembly), [The x86-64 instruction set](https://asm-editor.specy.app/learn/courses/x86/introduction/the-x86-instruction-set.md) (x86-64 assembly), [Effective addresses](https://asm-editor.specy.app/learn/courses/x86/introduction/effective-addresses.md) (x86-64 assembly), [The flags register](https://asm-editor.specy.app/learn/courses/x86/introduction/the-flags-register.md) (x86-64 assembly), [Sections, directives and labels](https://asm-editor.specy.app/learn/courses/x86/introduction/sections-directives-and-labels.md) (x86-64 assembly), [Memory regions and executable files](https://asm-editor.specy.app/learn/courses/x86/introduction/memory-regions-and-executable-files.md) (x86-64 assembly), [cmp and the conditional jumps](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/cmp-and-the-conditional-jumps.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

- `mov r/m, reg` (8, 16, 32, 64)
  - `mov r/m8, reg8`
  - `mov r/m16, reg16`
  - `mov r/m32, reg32`: 386 and later
  - `mov r/m64, reg64`
- `mov reg, r/m` (8, 16, 32, 64)
  - `mov reg8, r/m8`
  - `mov reg16, r/m16`
  - `mov reg32, r/m32`: 386 and later
  - `mov reg64, r/m64`
- `mov reg, imm` (8, 16, 32, 64)
  - `mov reg64, imm32`
  - `mov reg8, imm8`
  - `mov reg16, imm16`
  - `mov reg32, imm32`: 386 and later
  - `mov reg64, imm64`
- `mov r/m, imm` (8, 16, 32, 64)
  - `mov r/m8, imm8`
  - `mov r/m16, imm16`
  - `mov r/m32, imm32`: 386 and later
  - `mov r/m64, imm32`
- `mov mem16, segreg`
- `mov reg, segreg` (16, 32, 64)
  - `mov reg16, segreg`
  - `mov reg32, segreg`: 386 and later
  - `mov reg64, segreg`
- `mov segreg, mem16`
- `mov segreg, reg` (16, 32, 64)
  - `mov segreg, reg16`
  - `mov segreg, reg32`: 386 and later
  - `mov segreg, reg64`
- `mov acc, moffs` (8, 16, 32, 64)
  - `mov al, moffs`
  - `mov ax, moffs`
  - `mov eax, moffs`: 386 and later
  - `mov rax, moffs`
- `mov moffs, acc` (8, 16, 32, 64)
  - `mov moffs, al`
  - `mov moffs, ax`
  - `mov moffs, eax`: 386 and later
  - `mov moffs, rax`

## 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 reg64, creg`
- `mov creg, reg64`
- `mov reg64, dreg`
- `mov dreg, reg64`

## 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.

## Description

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.

## Example

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