Objective
Write a Program for Simulating AAA Instruction in assembly language.
AAA instruction stands for ASCII Adjust for Addition. It is used whenever we want to add two decimal digits which are Representative in ASCII code, without masking off “3” in upper nibble. In our program AAA instruction is not available in the instruction set of 8086. So we will first accept the two digits in AL and BL registers. Then we will mask the upper nibble i.e. “3” from AL and BL register by ANDing with 0F H, so that we will get LSB of two numbers. Then the two numbers are added.
Result of addition is in AL. We will check if the result is valid BCD. If addition > 9, then result is invalid BCD and to make it valid we will add 6. If result is valid, display the result.
Algorithm for Simulating AAA Instruction
Step I : Initialize the data segment.
Step II : Load number 1 in AL.
Step III : Load number 2 in BL.
Step IV : Mask the number 1 and store result in AL.
Step V : Mask number 2 and store result in BL.
Step VI : Add = number 1 + number 2.
Step VII : Check if addition < 9. If yes go to step IX. else go to step VIII.
Step VIII : Add 6 to make the result valid.
Step IX : Display the result.
Program for Simulating AAA Instruction
.model small
.data
a db 39H
b db 32H
.code
mov ax, @data ; Initialize data section
mov ds, ax
mov al, a ; Load number1 in al
mov bl, b ; Load number2 in bl
and al, 0fh ; unmask numbers and result in al
and bl, 0fh ; unmask numbers and result in al
add al, bl ; add the numbers in al and bl
cmp al, 09h ; check if no is valid BCD
jb next
add al, 06h ; for invalid BCD add 6 to
; make it valid
next: mov ch, 02h ; Count of digits to be
; displayed
mov cl, 04h ; Count to roll by 4 bits
mov bh, al ; Result in reg bh
l2: rol bh, cl ; roll bl so that msb comes
; to lsb
mov dl, bh ; load dl with data to be
; displayed
and dl, 0fH ; get only lsb
cmp dl, 09 ; check if digit is 0-9 or
; letter A-F
jbe l4
add dl, 07 ; if letter add 37H
; else only add 30H
l4: add dl, 30H
mov ah, 02 ; Function 2 under INT
; 21H (Display character)
int 21H
dec ch ; Decrement Count
jnz l2
mov ah, 4cH ; Terminate Program
int 21H
end
How to Run this Program
For Running this program you should have installed Tasm on you computer . If you have not installed Tasm yet please install from Here .
C:\programs>tasm aaa.asmTurbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland InternationalAssembling file: aaa.asmError messages: NoneWarning messages: NonePasses: 1Remaining memory: 438kC:\programs>tlink aaaTurbo Link Version 3.0 Copyright (c) 1987, 1990 Borland InternationalWarning: No stackC:\programs>aaa11
Leave a Reply