The DAA instruction
Decimal adjust of the AL register after addition.
The DAA instruction format
| Instruction | Description |
|---|---|
| DAA | Decimal adjust of the AL register after addition. |
Adjusts the sum of two packed BCD values to create a packed BCD result. The al register is an implied source and destination operand. The daa instruction is useful only when it follows the add instruction, which adds (binary addition) two 2-digit packed BCD values and stores the result in a byte in the al register. Then the daa instruction adjusts the contents of the al register so that it contains a correct 2-digit packed BCD result. If a decimal carry is detected, the CF and AF flags are set accordingly.
First example: 38 + 45
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov al, 38h ; Copy the packed value 38 into the al register mov bl, 45h ; Copy the packed value 45 into the bl register add al, bl ; Add the value in bl to the al register daa ; Adjust the contents of the al register mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Second example: 88 + 74 + 75 + 87 with output to the screen
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov al, 88h ; Copy the packed value 88 into the al register add al, 74h ; Add the packed value 74 to the al register daa ; Adjust the contents of the al register adc ah, 0 ; Perform addition with carry: ah + 0 add al, 75h ; Add the packed value 75 to the al register daa ; Adjust the contents of the al register adc ah, 0 ; Perform addition with carry: ah + 0 add al, 87h ; Add the packed value 87 to the al register daa ; Adjust the contents of the al register adc ah, 0 ; Perform addition with carry: ah + 0 mov bx, ax ; Copy the value of the ax register into the bx register mov ah, 02h ; Copy the console output function number into ah mov dl, bh ; Copy the number from the bh register into the dl register or dl, 30h ; Convert the value in the dl register into an ASCII digit int 21h ; Call the interrupt mov cl, 4 ; Copy the number 4 into the cl register shl bx, cl ; Shift the bits in bx to the left by the amount specified in cl mov dl, bh ; Copy the number from the bh register into the dl register or dl, 30h ; Convert the value in the dl register into an ASCII digit int 21h ; Call the interrupt shr bx, cl ; Shift the bits in bx to the right by the amount specified in cl and bl, 0Fh ; Clear the high nibble of the bl register mov dl, bl ; Copy the number from the bl register into the dl register or dl, 30h ; Convert the value in the dl register into an ASCII digit int 21h ; Call the interrupt mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Processor status flags
CF
YesPF
YesAF
YesZF
YesSF
YesTF
NoIF
NoDF
NoOF
?