Opcode | Encoding | 16-bit | 32-bit | 64-bit | Description |
---|---|---|---|---|---|
37 AAA | zo | Valid | Valid | Invalid | ASCII adjust AL after addition. |
Encoding
Encoding | Operand |
---|---|
zo | None |
Description
The AAA
instruction converts the result of an addition of two (unpacked) 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 DAA
(Decimal Adjust AL
After Addition) instruction handles that case.
Traditionally, this instruction is 'ASCII Adjust After Addition'. 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 AAA()
{
if ((AL & 0xF) > 9 || EFLAGS.AF)
AX += 0x106;
}
- According to Bochs' source code (
/cpu/bcd.cc
), this instruction is implemented differently on the 8086, 8088, and 80186 architectures. On them, the addition toAX
is performed as two separate operations: adding1
toAH
and adding6
toAL
. In practice, this makes no difference when true BCD digits are used (i.e. nothing outside00h
through09h
)
Example
mov ax, 0x106 ; 16 (decimal) in BCD
add al, 5 ; AX == 0x10B
aaa ; AX == 0x202 (22 (decimal) in BCD)
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
Exception | Mode | Cause of Exception | |||
---|---|---|---|---|---|
Real Mode | Virtual 8086 | Protected and Compatibility | Long Mode | ||
#UD | X | X | X | If the LOCK prefix is used. | |
X | If in Long Mode. |