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 al = AX / divisor;
    U16 ah = AX % divisor;
    if (ah > 0xFF)
        #DE;
    AL = (U8)al;
    AH = (U8)ah;
}
public void DIV(U16 divisor)
{
    if (divisor is 0)
        #DE;

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

    U64 eax = EDX:EAX / divisor;
    U64 edx = EDX:EAX % divisor;
    if (eax > 0xFFFF_FFFF)
        #DE;
    EAX = (U32)eax;
    EDX = (U32)edx;
}
public void DIV(U64 divisor)
{
    if (divisor is 0)
        #DE;

    U128 rax = RDX:RAX / divisor;
    U128 rdx = RDX:RAX % divisor;
    if (rax > 0xFFFF_FFFF_FFFF_FFFF)
        #DE;
    RAX = (U64)rax;
    RDX = (U64)rdx;
}

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.