The AAA instruction
Adjusting the AL register after addition.
The AAA instruction format
| Instruction | Description |
|---|---|
| AAA | Adjusting the AL register after addition |
Adjusts the sum of two unpacked BCD values to create an unpacked BCD result. The al register is the implied source and destination operand for this instruction. The aaa instruction is useful only when it follows an add instruction that adds (binary addition) two unpacked BCD values and stores a byte result in the al register. The aaa instruction then adjusts the contents of the al register so that it contains the correct 1-digit unpacked BCD result.
If the addition produces a decimal carry, the ah register is incremented by 1 and the CF and AF flags are set. If there is no decimal carry, the CF and AF flags are cleared and the ah register is left unchanged. In either case, bits 4 through 7 of the al register are cleared to 0.
First example: 5 + 7
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, 5 ; Copy the value 5 into the al register mov bl, 7 ; Copy the value 7 into the bl register add al, bl ; Add the value in the bl register to the al register aaa ; 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: 17 + 6 + 9 with screen output
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov ax, 0107h ; Copy the unpacked value 17 into the ax register add al, 6 ; Add the value 6 to the al register aaa ; Adjust the contents of the al register add al, 9 ; Add the value 9 to the al register aaa ; Adjust the contents of the al register mov bx, ax ; Save the value of the ax register in the bx register or bx, 3030h ; Convert the value in the bx register into an ASCII number mov ah, 02h ; Copy the console output function number into ah mov dl, bh ; Copy the ASCII number from the bh register into the dl register int 21h ; Call the interrupt mov dl, bl ; Copy the ASCII number from the bl register into the dl register 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)".