MOV and data transfer

Basic moves

MOV copies data between registers, between a register and memory, or from a constant into a register or memory. It never moves memory to memory directly:

mov rax, rbx ; register to register mov rax, 42 ; constant to register mov [buf], rax ; register to memory mov rax, [buf] ; memory to register

The rules

Both operands must be the same size. The destination cannot be a constant. And a segment register needs a special move, not a plain MOV:

mov eax, ebx ; ok: both 32-bit ; mov eax, bx ; error: size mismatch

Common traps

MOV is not assignment in C: it copies bits, it does not evaluate anything. MOV [mem], [mem] is illegal, so a memory-to-memory copy goes through a register. And MOV to a 32-bit register clears the upper half of the 64-bit register, which surprises people porting 32-bit code.

Next: Number bases and operands

Article author: Arthur Isaev