aaa
ASCII Adjust After Addition
AAA
Adjusts AL after addition for unpacked BCD.
Details
Adjusts AL after addition of two unpacked BCD (Binary Coded Decimal) digits, correcting the result to ensure valid BCD. If the lower nibble of AL is greater than 9 or the AF flag is set, AL is adjusted by adding 6 to the lower nibble and 1 is added to AH. The AF and CF flags are set or cleared accordingly. This instruction is invalid in 64-bit mode and is primarily legacy.
Pseudocode Operation
if ((AL & 0x0F) > 9 || AF == 1) { AL ← (AL + 6) & 0xFF; AH ← AH + 1; AF ← 1; CF ← 1 } else { AF ← 0; CF ← 0 }; AL ← AL & 0x0F
Example
AAA
Encoding
Binary Layout
37
+0
Operands
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| 37 | AAA | ZO | Invalid Valid | ASCII adjust AL after addition. |
Description
Adjusts the sum of two unpacked BCD values to create an unpacked BCD result. The AL register is the implied source and destination operand for this instruction. The AAA instruction is only useful when it follows an ADD instruction that adds (binary addition) two unpacked BCD values and stores a byte result in the AL register. The
AAA instruction then adjusts the contents of the AL register to contain the correct 1-digit unpacked BCD result.
If the addition produces a decimal carry, the AH register increments by 1, and the CF and AF flags are set. If there was no decimal carry, the CF and AF flags are cleared and the AH register is unchanged. In either case, bits 4 through 7 of the AL register are set to 0.
This instruction executes as described in compatibility mode and legacy mode. It is not valid in 64-bit mode.
Operation
IF 64-Bit Mode THEN #UD; ELSE IF ((AL AND 0FH) > 9) or (AF = 1) THEN AX := AX + 106H; AF := 1; CF := 1; ELSE AF := 0; CF := 0; FI; AL := AL AND 0FH; FI;
Flags Affected
The AF and CF flags are set to 1 if the adjustment results in a decimal carry; otherwise they are set to 0. The OF, SF, ZF, and PF flags are undefined.
Exceptions
Protected Mode Exceptions
#UD If the LOCK prefix is used.
Real-Address Mode Exceptions
Same exceptions as protected mode.
Virtual-8086 Mode Exceptions
Same exceptions as protected mode.
AAA—ASCII Adjust After Addition Vol. 2A 3-1
Compatibility Mode Exceptions
Same exceptions as protected mode.
64-Bit Mode Exceptions
#UD If in 64-bit mode.
AAA—ASCII Adjust After Addition Vol. 2A 3-2