Decimal Adjust AL After Addition

Encoding

EncodingOperand
zoNone

Description

The DAA instruction converts the result of an addition of two (packed) BCD digits to a valid 2-digit BCD number.

An "packed" BCD number is one where each byte contains two digits – one in each nibble. In contrast, an unpacked BCD number is one where each byte contains a single digit. The AAA (ASCII Adjust AL After Addition) instruction handles that case.

This instruction is not valid in Long Mode.

Operation

public void DAA()
{
    byte oldAL = AL;
    bool oldCF = EFLAGS.CF; // CF could be set in the ones place adjustment

    // adjust ones place
    if ((AL & 0xF) > 9 || EFLAGS.AF)
        AL += 6;

    // adjust tens place
    if (oldAL > 0x99 || oldCF)
        AL += 0x60;
}

Example

mov al, 0x79 ; 79 (decimal) in packed BCD
add al, 0x35 ; AL == 0xAE
daa          ; AL == 0x14 with carry set (giving 0x114)

Flags Affected

CF (carry flag)
Set if an adjustment results in a decimal carry in either digit. Cleared otherwise.
PF (parity flag)
Set according to the result.
AF (auxiliary flag)
Set if an adjustment results in a decimal carry in either digit. Cleared otherwise.
ZF (zero flag)
Set according to the result.
SF (sign flag)
Set according to the result.
OF (overflow flag)
Undefined.

Exceptions

Real-Address Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Virtual-8086 Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Protected Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Compatibility Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Long Mode

#UD
  • If in Long Mode.