Unsigned Divide

Encoding

EncodingOperand
mModRM.r/m[rw]

Description

The DIV instruction performs an unsigned divide by the operand. For 8 bit operand size, the dividend is located AH, and the quotient is stored AL and the remainder in AH. For non-8 bit operand sizes, the located in the rDX:rAX register pair, and the quotient is stored in rAX and the remainder in rDX.

Non-integral results are truncated ("chopped") towards zero. Overflow is indicated by the #DE exception rather than EFLAGS.CF.

Operation

public void DIV(U8 divisor)
{
    if (divisor is 0)
        #DE;

    U16 temp = AX / divisor;
    if (temp > 0xFF)
        #DE;
    AL = (U8)temp;
    AH = (U8)(AX % divisor);
}
public void DIV(U16 divisor)
{
    if (divisor is 0)
        #DE;

    U32 temp = DX:AX / divisor;
    if (temp > 0xFFFF)
        #DE;
    AX = (U16)temp;
    DX = (U16)(DX:AX % divisor);
}
public void DIV(U32 divisor)
{
    if (divisor is 0)
        #DE;

    U64 temp = EDX:EAX / divisor;
    if (temp > 0xFFFFFFFF)
        #DE;
    EAX = (U16)temp;
    EDX = (U16)(EDX:EAX % divisor);
}
public void DIV(U64 divisor)
{
    if (divisor is 0)
        #DE;

    U128 temp = RDX:RAX / divisor;
    if (temp > 0xFFFFFFFFFFFFFFFF)
        #DE;
    RAX = (U16)temp;
    RDX = (U16)(RDX:RAX % divisor);
}

Flags Affected

CF (carry flag)
Undefined.
PF (parity flag)
Undefined.
AF (auxiliary flag)
Undefined.
ZF (zero flag)
Undefined.
SF (sign flag)
Undefined.
OF (overflow flag)
Undefined.

Intrinsics

None. Auto-generated by compiler.

Exceptions

Real-Address Mode

#DE
  • If the source operand (divisor) is 0.
  • If the quotient (result) is too large for the destination register.
#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.

Virtual-8086 Mode

#DE
  • If the source operand (divisor) is 0.
  • If the quotient (result) is too large for the destination register.
#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.

Protected Mode

#DE
  • If the source operand (divisor) is 0.
  • If the quotient (result) is too large for the destination register.
#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If the destination is located in a non-writable segment.
  • If a memory operand uses a segment containing a NULL selector.
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.

Compatibility Mode

#DE
  • If the source operand (divisor) is 0.
  • If the quotient (result) is too large for the destination register.
#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If the destination is located in a non-writable segment.
  • If a memory operand uses a segment containing a NULL selector.
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.

Long Mode

#DE
  • If the source operand (divisor) is 0.
  • If the quotient (result) is too large for the destination register.
#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment is in non-canonical form.
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If a memory operand (using a segment other than SS) is in non-canonical form.
  • If the destination is located in a non-writable segment.
  • If a memory operand uses a segment containing a NULL selector.
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.