ASCII Adjust AX After Subtraction

Encoding

EncodingOperand
zoNone

Description

The AAS instruction converts the result of a subtraction of two BCD digits to a valid 2-digit BCD number.

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

Traditionally, this instruction is 'ASCII Adjust After Subtraction'. 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).

This instruction is not valid in Long Mode.

Operation

public void AAS(U8 imm8)
{
    if ((AL & 0xF) > 9 || EFLAGS.AF)
        AX -= 0x106;
    AL &= 0xF;
}

Flags Affected

CF (carry flag)
Set if an adjustment is made. Cleared otherwise.
PF (parity flag)
Undefined.
AF (auxiliary flag)
Set if an adjustment is made. Cleared otherwise.
ZF (zero flag)
Undefined.
SF (sign flag)
Undefined.
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.