Decimal Adjust AL After Subtraction

Encoding

EncodingOperand
zoNone

Description

The DAS instruction converts the result of a subtraction 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 AAS (ASCII Adjust AL After Subtraction) instruction handles that case.

This instruction is not valid in Long Mode.

Operation

public void DAS()
{
    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, 0x35 ; 35 (decimal) in packed BCD
sub al, 0x79 ; AL == 0xBC
das          ; AL == 0x56 with carry set (giving -0x44)

Flags Affected

CF (carry flag)
Set if an adjustment results in a decimal borrow into either digit. Cleared otherwise.
PF (parity flag)
Set according to the result.
AF (auxiliary flag)
Set if an adjustment results in a decimal borrow into 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.