ARPL: Adjust RPL Field of Segment Selector

For information about interpreting this page, see the help page.
Opcode and MnemonicEncoding16 bit Mode32 bit Mode64 bit ModeDescription
63 /r
ARPL r/m16, r16
MRInvalidValidNot EncodableAdjusts the RPL field of r/m16 to be greater than or equal to the RPL field of r16.

Encoding

EncodingOperand 1Operand 2
MRModRM.r/m[rw]ModRM.reg[r]

Description

The ARPL instruction compares the RPL (requested privilege level) field (bits 0 and 1) of two segment selectors. If the RPL field of the destination operand is less than the RPL field of the source operand, the ZF flag is set and the RPL field of the destination is increased to match the source's. Otherwise, the ZF flag is cleared and no change to the destination occurs.

This instruction is is not valid in 16 bit mode, and, if encountered, the processor will raise a #UD exception.

This instruction is not encodable in 64 bit mode, and, if encountered, will be treated as the MOVSXD instruction.

Operation

This pseudo-code uses C# syntax. A list of the types used is available here.
public void ARPL(ref ushort dest, ushort src)
{
  // lowest two bits
  if (dest.Bit[0..2] < src.Bit[0..2])
  {
    dest.Bit[0..2] = src.Bit[0..2];
    ZF = 1;
  }
  else
  {
    ZF = 0;
  }
}

Flags Affected

CF (carry flag)
???
PF (parity flag)
???
AF (auxiliary flag)
???
ZF (zero flag)
Set if the destination operand is changed.
SF (sign flag)
???
OF (overflow flag)
???

Exceptions

Protected Mode

#GP(0)
If the destination is located 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 is used to access memory and it contains a NULL segment selector.
#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 while the current privilege level is 3.
#UD
If the LOCK prefix is used.

Real-Address Mode

#UD
If in 16 bit mode.

Virtual-8086 Mode

#UD
If in 16 bit mode.

Compatibility Mode

Same exceptions as in protected mode.

Long Mode

Not encodable.