ASCII Adjust AX Before Division

Encoding

EncodingOperand
zoNone (implicitly 10)
iimm8

Description

The AAD instruction prepares a BCD number for division. It does so by converting the number in AX back into binary.

Traditionally, this instruction is 'ASCII Adjust Before Division'. This would lead one to believe that it works on ASCII digits (30h ("0") through 39h ('9')), however, this is incorrect. This instruction actually operates on binary coded decimal (BCD) digits (00h through 09h).

Due to a quirk of history, this instruction encodes the base of the result in the instruction (the second byte). As such, it is possible to have this instruction work on other bases through an immediate 8 bit operand. Such methods are not guaranteed to be supported by your assembler, and in such situations, one must encode the instruction directly.

This instruction is not valid in Long Mode.

Operation

public void AAD(U8 imm8)
{
    AL += AH * imm8;
    AH = 0;
}

Flags Affected

CF (carry flag)
Undefined.
PF (parity flag)
Set according to the result.
AF (auxiliary flag)
Undefined.
ZF (zero flag)
Set according to the result.
SF (sign flag)
Set according to the result.
OF (overflow flag)
Undefined.

Exceptions

ExceptionModeCause of Exception
Real
Mode
Virtual
8086
Protected and CompatibilityLong
Mode
#UDXXX If the LOCK prefix is used.
XIf in Long Mode.