MOV

Move

Opcodes

Hex Mnemonic Encoding Long Mode Legacy Mode Description
A3 MOV moffs32*,EAX D Valid Valid Move EAX to (seg:offset).
A3 MOV moffs16*,AX D Valid Valid Move AX to (seg:offset).
REX.W + A2 MOV moffs8***,AL D Valid N.E. Move AL to (offset).
A2 MOV moffs8,AL D Valid Valid Move AL to (seg:offset).
REX.W + A1 MOV RAX,moffs64* C Valid N.E. Move quadword at (offset) to RAX.
A1 MOV EAX,moffs32* C Valid Valid Move doubleword at (seg:offset) to EAX.
A1 MOV AX,moffs16* C Valid Valid Move word at (seg:offset) to AX.
REX.W + A0 MOV AL,moffs8* C Valid N.E. Move byte at (offset) to AL.
A0 MOV AL,moffs8* C Valid Valid Move byte at (seg:offset) to AL.
REX.W + 8E /r MOV Sreg,r/m64** B Valid Valid Move lower 16 bits of r/m64 to segment register.
8E /r MOV Sreg,r/m16** B Valid Valid Move r/m16 to segment register.
REX.W + 8C /r MOV r/m64,Sreg** A Valid Valid Move zero extended 16-bit segment register to r/m64.
8C /r MOV r/m16,Sreg** A Valid Valid Move segment register to r/m16.
REX.W + 8B /r MOV r64,r/m64 B Valid N.E. Move r/m64 to r64.
8B /r MOV r32,r/m32 B Valid Valid Move r/m32 to r32.
8B /r MOV r16,r/m16 B Valid Valid Move r/m16 to r16.
REX + 8A /r MOV r8***,r/m8*** B Valid N.E. Move r/m8 to r8.
8A /r MOV r8,r/m8 B Valid Valid Move r/m8 to r8.
REX.W + 89 /r MOV r/m64,r64 A Valid N.E. Move r64 to r/m64.
89 /r MOV r/m32,r32 A Valid Valid Move r32 to r/m32.
89 /r MOV r/m16,r16 A Valid Valid Move r16 to r/m16.
REX + 88 /r MOV r/m8***,r8 *** A Valid N.E. Move r8 to r/m8.
88 /r MOV r/m8,r8 A Valid Valid Move r8 to r/m8.

Instruction Operand Encoding

Op/En Operand 0 Operand 1 Operand 2 Operand 3
A NA NA ModRM:reg (r) ModRM:r/m (w)
B NA NA ModRM:r/m (r) ModRM:reg (w)
C NA NA Displacement AL/AX/EAX/RAX
D NA NA AL/AX/EAX/RAX Displacement
E NA NA imm8/16/32/64 reg (w)
F NA NA imm8/16/32/64 ModRM:r/m (w)

Description

Copies the second operand (source operand) to the first operand (destination operand). The source operand can be an immediate value, general-purpose register, segment register, or memory location; the destination register can be a general-purpose register, segment register, or memory location. Both operands must be the same size, which can be a byte, a word, a doubleword, or a quadword.

The MOV instruction cannot be used to load the CS register. Attempting to do so results in an invalid opcode exception (#UD). To load the CS register, use the far JMP, CALL, or RET instruction.

If the destination operand is a segment register (DS, ES, FS, GS, or SS), the source operand must be a valid segment selector. In protected mode, moving a segment selector into a segment register automatically causes the segment descriptor information associated with that segment selector to be loaded into the hidden (shadow) part of the segment register. While loading this information, the segment selector and segment descriptor information is validated (see the "Operation" algorithm below). The segment descriptor data is obtained from the GDT or LDT entry for the specified segment selector.

A NULL segment selector (values 0000-0003) can be loaded into the DS, ES, FS, and GS registers without causing a protection exception. However, any subsequent attempt to reference a segment whose corresponding segment register is loaded with a NULL value causes a general protection exception (#GP) and no memory reference occurs.

Loading the SS register with a MOV instruction inhibits all interrupts until after the execution of the next instruction. This operation allows a stack pointer to be loaded into the ESP register with the next instruction (MOV ESP, stack-pointer value) before an interrupt occurs1. Be aware that the LSS instruction offers a more efficient method of loading the SS and ESP registers.

When operating in 32-bit mode and moving data between a segment register and a general-purpose register, the 32-bit IA-32 processors do not require the use of the 16-bit operand-size prefix (a byte with the value 66H) with this instruction, but most assemblers will insert it if the standard form of the instruction is used (for example, MOV DS, AX). The processor will execute this instruction correctly, but it will usually require an extra clock. With most assemblers, using the instruction form MOV DS, EAX will avoid this unneeded 66H prefix. When the processor executes the instruction with a 32-bit general-purpose register, it assumes that the 16 least-significant bits of the general-purpose register are the destination or source operand. If the register is a destination operand, the resulting value in the two high-order bytes of the register is implementation dependent. For the Pentium 4, Intel Xeon, and P6 family processors, the two high-order bytes are filled with zeros; for earlier 32-bit IA-32 processors, the two high order bytes are undefined.

In 64-bit mode, the instruction's default operation size is 32 bits. Use of the REX.R prefix permits access to additional registers (R8-R15). Use of the REX.W prefix promotes operation to 64 bits. See the summary chart at the beginning of this section for encoding data and limits.

Pseudo Code

DEST = SRC;
(* Loading a segment register while in protected mode results in special checks and actions, as described in the following listing. These checks are performed on the segment selector and the segment descriptor to which it points. *)
IF SS is loaded
	IF segment selector is NULL
		#GP(0);
	FI;
	IF segment selector index is outside descriptor table limits or segment selector's RPL != CPL or segment is not a writable data segment or DPL != CPL
		#GP(selector);
	FI;
	IF segment not marked present
		#SS(selector);
	ELSE
		SS = segment selector;
		SS = segment descriptor;
	FI;
FI;
IF DS, ES, FS, or GS is loaded with non-NULL selector
	IF segment selector index is outside descriptor table limits or segment is not a data or readable code segment or ((segment is a data or nonconforming code segment) and (both RPL and CPL > DPL))
		#GP(selector);
	FI;
	IF segment not marked present
		#NP(selector);
	ELSE
		SegmentRegister = segment selector;
		SegmentRegister = segment descriptor;
	FI;
FI;
IF DS, ES, FS, or GS is loaded with NULL selector
	SegmentRegister = segment selector;
	SegmentRegister = segment descriptor;
FI;

Flags Affected

None.

Exceptions

64-Bit Mode Exceptions

Exception Description
#UD If attempt is made to load the CS register. If the LOCK prefix is used.
#AC(0) If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#PF(fault-code) If a page fault occurs.
#SS(selector) If the SS register is being loaded and the segment pointed to is marked not present.
#SS(0) If the stack address is in a non-canonical form.
#GP(selector) If segment selector index is outside descriptor table limits. If the memory access to the descriptor table is non-canonical. If the SS register is being loaded and the segment selector's RPL and the segment descriptor's DPL are not equal to the CPL. If the SS register is being loaded and the segment pointed to is a nonwritable data segment. If the DS, ES, FS, or GS register is being loaded and the segment pointed to is not a data or readable code segment. If the DS, ES, FS, or GS register is being loaded and the segment pointed to is a data or nonconforming code segment, but both the RPL and the CPL are greater than the DPL.
#GP(0) If the memory address is in a non-canonical form. If an attempt is made to load SS register with NULL segment selector when CPL = 3. If an attempt is made to load SS register with NULL segment selector when CPL < 3 and CPL != RPL.

Compatibility Mode Exceptions

Same exceptions as in protected mode.

Virtual-8086 Mode Exceptions

Exception Description
#UD If attempt is made to load the CS register. If the LOCK prefix is used.
#AC(0) If alignment checking is enabled and an unaligned memory reference is made.
#PF(fault-code) If a page fault occurs.
#SS(0) If a memory operand effective address is outside the SS segment limit.
#GP(0) If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.

Real-Address Mode Exceptions

Exception Description
#UD If attempt is made to load the CS register. If the LOCK prefix is used.
#SS If a memory operand effective address is outside the SS segment limit.
#GP If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.

Protected Mode Exceptions

Exception Description
#UD If attempt is made to load the CS register. If the LOCK prefix is used.
#AC(0) If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#PF(fault-code) If a page fault occurs.
#NP If the DS, ES, FS, or GS register is being loaded and the segment pointed to is marked not present.
#SS(selector) If the SS register is being loaded and the segment pointed to is marked not present.
#SS(0) If a memory operand effective address is outside the SS segment limit.
#GP(selector) If segment selector index is outside descriptor table limits. If the SS register is being loaded and the segment selector's RPL and the segment descriptor's DPL are not equal to the CPL. If the SS register is being loaded and the segment pointed to is a non-writable data segment. If the DS, ES, FS, or GS register is being loaded and the segment pointed to is not a data or readable code segment. If the DS, ES, FS, or GS register is being loaded and the segment pointed to is a data or nonconforming code segment, but both the RPL and the CPL are greater than the DPL.
#GP(0) If attempt is made to load SS register with NULL segment selector. If the destination operand is in a non-writable segment. If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit. If the DS, ES, FS, or GS register contains a NULL segment selector.