daa
decimal-adjust AL -> AL
Use daa only after executing the form of an add instruction that stores a two-BCD-digit byte result in the AL register. daa then adjusts AL to a two-digit packed decimal result.
Decimal adjust the two-BCD-digit in the AL register:
daa
das
decimal-adjust AL -> AL
Use das only after executing the form of a sub instruction that stores a two-BCD-digit byte result in the AL register. das then adjusts AL to a two-digit packed decimal result.
Decimal adjust the two-BCD-digit in the AL register:
das
aaa
ASCII-adjust AL -> AL
You use aaa only after executing the form of an add instruction that stores a two-BCD-digit byte result in the AL register. aaa then adjusts AL to contain the correct decimal result. The top nibble of AL is set to 0. To convert AL to an ASCII result, follow the aaa instruction with:
or %al, 0x30
The following table shows how aaa handles a carry.
Table 2-8 aaa Handling a Carry
Carry |
Action |
---|---|
decimal carry |
AH + 1; CF and AF set to 1 |
no decimal carry |
AH unchanged; CF and AF cleared to 0 |
Adjust the AL register to contain the correct decimal result after an add instruction that stores a two-BCD-digit byte.
aaa
aas
ASCII-adjust AL -> AL
Use aas only after executing the form of an add instruction that stores a two-BCD-digit byte result in the AL register. aas then adjusts AL to contain the correct decimal result. The top nibble of AL is set to 0. To convert AL to an ASCII result, follow the aas instruction with:
or %al, 0x30
Table 2-9 shows how aas handles a carry.
Table 2-9 How aas Handles a Carry
Carry |
Action |
---|---|
decimal carry |
AH - 1; CF and AF set to 1 |
no decimal carry |
AH unchanged; CF and AF cleared to 0 |
Adjust the AL register to contain the correct decimal result after a sub instruction that stores a two-BCD-digit byte
aas
aam
AL 10 -> AH mod 10 AL -> AL
You use aam only after executing a mul instruction between two BCD digits (unpacked). mul stores the result in the AX register. The result is less than 100 so it can be contained in the AL register (the low byte of the AX register). aam unpacks the AL result by dividing AL by 10, stores the quotient (most-significant digit) in AH, and stores the remainder (least-significant digit) in AL.
Adjust the AL register to contain the correct decimal result after a mul instruction between two BCD digits:
aam
aad
AL + (AH x 10) -> AL 0 -> AH
aad prepares two unpacked BCD digits for a division operation that yields an unpacked result. The least-significant digit is in AL; the most-significant in AH.
aad prepares the AL and AH registers:
AL + (AH x 10) -> AL 0 -> AH
AX is then equal to the binary equivalent of the original unpacked two-digit BCD number.
Adjust the AL and AH registers for a division operation by setting the AX register equal to the original unpacked two-digit number:
aad