2. DECIMAL ADJUST AFTER ADDITION
• The DAA (Decimal Adjust after Addition) instruction allows
addition of numbers represented in 8-bit packed BCD code. It is
used immediately after normal addition instruction operating on
BCD codes.
• This instruction assumes the AL register as the source and the
destination, and hence it requires no operand.
• The effect of DAS (Decimal Adjust after Subtraction) instruction is
similar to that of DAA, except that it is used after a subtraction
instruction.
MP
5. FLAGS AND REGISTER AFFECTED
• The CF and AF flags are set if the adjustment of the value results
in a decimal carry in either digit of the result (see the
“Operation” section above). The SF, ZF, and PF flags are set
according to the result. The OF flag is undefined.
MP
6. SAMPLE CODE
.model small
.data
d1 dw 45h ;moving 45 as packed BCD
d2 dw 45h ;moving 45 as packed BCD
.code
mov ax,@data
mov ds,ax
mov ax,d1
mov bx,d2
add ax,bx
daa ;adjusting the packed BCD after addition
end
MP
7. DECIMAL ADJUST AL AFTER SUBTRACTION
• Adjusts the result of the subtraction of two packed BCD values to
create a packed BCD result.
• The AL register is the implied source and destination operand.
• The DAS instruction is only useful when it follows a SUB instruction
that subtracts (binary subtraction) one 2-digit, packed BCD value
from another and stores a byte result in the AL register.
• The DAS instruction then adjusts the contents of the AL register to
contain the correct 2-digit, packed BCD result. If a decimal borrow
is detected, the CF and AF flags are set accordingly.
MP
8. EXAMPLE
• Example: SUB AL, BL
• Before:
AL=35H BL=47H EFLAGS(OSZAPC)=XXXXXX
After: AL=EEH BL=47H EFLAGS(0SZAPC)=010111
MP
9. Example: Decimal adjust after subtraction
SUB AL,BL
AL=86H
BL=57H
SUB AL-BL=29H SUB 1000 0110
0101 0111 2’s complement is 10101001
1000 0110
1010 1001
0010 1111 LSB>9 Add -6
(2) (F) so 0010 1111
1010
0010 1001
• (2) (9)
MP
10. FLAGS AND REGISTER AFFECTED
• The CF and AF flags are set if the adjustment of the value results
in a decimal borrow in either digit of the result (see the
"Operation" section above). The SF, ZF, and PF flags are set
according to the result. The OF flag is undefined.
MP
11. SAMPLE CODE
.model small
.data
d1 dw 86h
d2 dw 57h
.code
mov ax,@data
mov ds,ax
mov ax,d1 ;moving 86 as packed BCD
mov bx,d2 ;moving 57 as packed BCD
sub ax,bx
das ; adjusting the packed BCD after subraction
MP