MOV

Move

stableVMJITAOTinstruction

Encodings

OpcodeInstructionOp/En64-bitCompat/LegacyDescription
88 /rMOV r/m8, r8MRValidValidMove r8 to r/m8.
89 /rMOV r/m16, r16MRValidValidMove r16 to r/m16.
89 /rMOV r/m3, r3MRValidValidMove r3 to r/m32.
REX.W + 89 /rMOV r/m64, r64MRValidNot encodableMove r64 to r/m64.
8A /rMOV r8, r/m8RMValidValidMove r/m8 to r8.
8B /rMOV r16, r/m16RMValidValidMove r/m16 to r16.
8B /rMOV r3, r/m3RMValidValidMove r/m3 to r32.
REX.W + 8B /rMOV r64, r/m64RMValidNot encodableMove r/m64 to r64.
8C /rMOV r/m16, Sreg2MRValidValidMove segment register to r/m16.
8C /rMOV r16/r32/m16, Sreg2MRValidValidMove zero extended 16-bit segment register to r16/r32/m16.
REX.W + 8C /rMOV r64/m16, Sreg2MRValidValidMove zero extended 16-bit segment register to r64/m16.
8E /rMOV Sreg, r/m16RMValidValidMove r/m16 to segment register.
REX.W + 8E /rMOV Sreg, r/m64RMValidValidMove lower 16 bits of r/m64 to segment register.
A0MOV AL, moffs8FDValidValidMove byte at (seg:offset) to AL.
REX.W + A0MOV AL, moffs8FDValidNot encodableMove byte at (offset) to AL.
A1MOV AX, moffs16FDValidValidMove word at (seg:offset) to AX.
A1MOV EAX, moffs32FDValidValidMove doubleword at (seg:offset) to EAX.
REX.W + A1MOV RAX, moffs64FDValidNot encodableMove quadword at (offset) to RAX.
A2MOV moffs8, ALTDValidValidMove AL to (seg:offset).
REX.W + A2MOV moffs8, ALTDValidNot encodableMove AL to (offset).
A3MOV moffs16, AXTDValidValidMove AX to (seg:offset).
A3MOV moffs32, EAXTDValidValidMove EAX to (seg:offset).
REX.W + A3MOV moffs64, RAXTDValidNot encodableMove RAX to (offset).
B0+ rb ibMOV r8, imm8OIValidValidMove imm8 to r8.
B8+ rw iwMOV r16, imm16OIValidValidMove imm16 to r16.
B8+ rd idMOV r3, imm3OIValidValidMove imm3 to r32.
REX.W + B8+ rd ioMOV r64, imm64OIValidNot encodableMove imm64 to r64.
C6 /0 ibMOV r/m8, imm8MIValidValidMove imm8 to r/m8.
C7 /0 iwMOV r/m16, imm16MIValidValidMove imm16 to r/m16.
C7 /0 idMOV r/m3, imm3MIValidValidMove imm3 to r/m32.
REX.W + C7 /0 idMOV r/m64, imm3MIValidNot encodableMove imm3 sign extended to 64-bits to r/m64.

Operand encoding

Each mode is a value of the Op/En column above. It says which field of the encoded instruction carries each operand, in the order they are written, and whether the instruction reads it, writes it or both.

MR

  1. modrm.rm escrituraModRM byte, r/m field (bits 2-0); with the SIB byte and the displacement when the mod field asks for them
  2. modrm.reg lecturaModRM byte, reg field (bits 5-3)

RM

  1. modrm.reg escrituraModRM byte, reg field (bits 5-3)
  2. modrm.rm lecturaModRM byte, r/m field (bits 2-0); with the SIB byte and the displacement when the mod field asks for them

FD

  1. AL/AX/EAX/RAX
  2. moffsabsolute address that follows the opcode

TD

  1. moffs escrituraabsolute address that follows the opcode
  2. AL/AX/EAX/RAX

OI

  1. opcode.reg escrituralow three bits of the opcode byte itself
  2. imm8/16/32/64immediate after the instruction, as wide as the operand

MI

  1. modrm.rm escrituraModRM byte, r/m field (bits 2-0); with the SIB byte and the displacement when the mod field asks for them
  2. imm8/16/32/64immediate after the instruction, as wide as the operand

Measured cost

Loading measurements from arch-data...

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 suppresses or inhibits some debug exceptions and inhibits interrupts on the following instruction boundary. (The inhibition ends after delivery of an exception or the execution of the next instruction.) This behavior allows a stack pointer to be loaded into the ESP register with the next instruction (MOV ESP, stack-pointer value) before an event can be delivered. See Section 7.8.3, "Masking Exceptions and Interrupts When Switching Stacks," in the Intel(R) 64 and IA-32 Architectures Software Developer's Manual, Volume 3A. Intel recommends that software use the LSS instruction to load the SS register and ESP together.

When executing MOV Reg, Sreg, the processor copies the content of Sreg to the 16 least significant bits of the general-purpose register. The upper bits of the destination register are zero for most IA-32 processors (Pentium Pro processors and later) and all Intel 64 processors, with the exception that bits 31:16 are undefined for Intel Quark X1000 processors, Pentium, and earlier processors.

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.

Operation

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
    THEN
          IF segment selector is NULL
                THEN #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

                THEN #GP(selector); FI;
          IF segment not marked present

                THEN #SS(selector);
                ELSE

                      SS := segment selector;
                      SS := segment descriptor; FI;
FI;

IF DS, ES, FS, or GS is loaded with non-NULL selector
THEN

    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 ((RPL > DPL) or (CPL > DPL)))

          THEN #GP(selector); FI;
    IF segment not marked present

          THEN #NP(selector);
          ELSE

                SegmentRegister := segment selector;
                SegmentRegister := segment descriptor; FI;
FI;

IF DS, ES, FS, or GS is loaded with NULL selector
    THEN
          SegmentRegister := segment selector;
          SegmentRegister := segment descriptor;

FI;

Flags affected

None.

Exceptions

Protected mode
#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.
#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, and either the RPL or the CPL is greater than the DPL.
#SS(0)If a memory operand effective address is outside the SS segment limit.
#SS(selector)If the SS register is being loaded and the segment pointed to is marked not present.
#NPIf the DS, ES, FS, or GS register is being loaded and the segment pointed to is marked not present. #PF(fault-code) If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#UDIf attempt is made to load the CS register. If the LOCK prefix is used.
Real address mode
#GPIf a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SSIf a memory operand effective address is outside the SS segment limit.
#UDIf attempt is made to load the CS register. If the LOCK prefix is used.
Virtual-8086 mode
#GP(0)If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SS(0)If a memory operand effective address is outside the SS segment limit. #PF(fault-code) If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made.
#UDIf attempt is made to load the CS register. If the LOCK prefix is used.
Compatibility mode
Same exceptions as in protected mode.
64-bit mode
#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.
#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.
#SS(0)If the stack address is in a non-canonical form.
#SS(selector)If the SS register is being loaded and the segment pointed to is marked not present. #PF(fault-code) If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#UDIf attempt is made to load the CS register. If the LOCK prefix is used.

Sources