6-28
INSTRUCTION SET SUMMARY
6.5.1.Packed BCD Adjustment Instructions
The DAA (decimal adjust after addition) and DAS (decimal adjust after subtraction) instructions
adjust the results of operations performed on packed BCD integers (refer to Section 5.2.3.,
BCD Integers in Chapter 5, Data Types and Addressing Modes). Adding two packed BCD
values requires two instructions: an ADD instruction followed by a DAA instruction. The ADD
instruction adds (binary addition) the two values and stores the result in the AL register. The
DAA instruction then adjusts the value in the AL register to obtain a valid, 2-digit, packed BCD
value and sets the CF flag if a decimal carry occurred as the result of the addition.
Likewise, subtracting one packed BCD value from another requires a SUB instruction followed
by a DAS instruction. The SUB instruction subtracts (binary subtraction) one BCD value from
another and stores the result in the AL register. The DAS instruction then adjusts the value in
the AL register to obtain a valid, 2-digit, packed BCD value and sets the CF flag if a decimal
borrow occurred as the result of the subtraction.
6.5.2.Unpacked BCD Adjustment Instructions
The AAA (ASCII adjust after addition), AAS (ASCII adjust after subtraction), AAM (ASCII
adjust after multiplication), and AAD (ASCII adjust before division) instructions adjust the
results of arithmetic operations performed in unpacked BCD values (refer to Section 5.2.3.,
BCD Integers in Chapter 5, Data Types and Addressing Modes). All these instructions assume
that the value to be adjusted is stored in the AL register or, in one instance, the AL and AH regis-
ters.
The AAA instruction adjusts the contents of the AL register following the addition of two
unpacked BCD values. It converts the binary value in the AL register into a decimal value and
stores the result in the AL register in unpacked BCD format (the decimal number is stored in the
lower 4 bits of the register and the upper 4 bits are cleared). If a decimal carry occurred as a result
of the addition, the CF flag is set and the contents of the AH register are incremented by 1.
The AAS instruction adjusts the contents of the AL register following the subtraction of two
unpacked BCD values. Here again, a binary value is converted into an unpacked BCD value. If
a borrow was required to complete the decimal subtract, the CF flag is set and the contents of
the AH register are decremented by 1.
The AAM instruction adjusts the contents of the AL register following a multiplication of two
unpacked BCD values. It converts the binary value in the AL register into a decimal value and
stores the least significant digit of the result in the AL register (in unpacked BCD format) and
the most significant digit, if there is one, in the AH register (also in unpacked BCD format).
The AAD instruction adjusts a two-digit BCD value so that when the value is divided with the
DIV instruction, a valid unpacked BCD result is obtained. The instruction converts the BCD
value in registers AH (most significant digit) and AL (least significant digit) into a binary value
and stores the result in register AL. When the value in AL is divided by an unpacked BCD value,
the quotient and remainder will be automatically encoded in unpacked BCD format.