DAA AND DAS

BasavarajSavalagi 6,543 views 11 slides Apr 23, 2018
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

DECIMAL ADJUST AFTER ADDITION AND DECIMAL ADJUST AFTER SUBTRACTION


Slide Content

DAA AND DAS Microprocessor Aat-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

EXAMPLE Example: ADD AL, BL Before: AL=79H BL=35H EFLAGS(OSZAPC)=XXXXXX After: AL=AEH BL=35H EFLAGS(0SZAPC)=110000 MP

EXAMPLE Decimal adjust after addition ADD AL,BL AL=45H BL=45H ADD AL+BL=90H ADD 0100 0101 0100 0101 1 1 1 1000 1010 LSB>9 Add 6 so 1000 1010 0110 1001 0000=90H MP

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

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

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

EXAMPLE Example: SUB AL, BL Before: AL=35H BL=47H EFLAGS(OSZAPC)=XXXXXX After: AL=EEH BL=47H EFLAGS(0SZAPC)=010111 MP

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

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

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 end MP
Tags