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
1 |
<span style="font-size: 14pt; font-family: 'times new roman', times, serif; color: #000000;"><code> .model small <br/> .data <br/> a db 39H <br/> b db 32H <br/> .code <br/> mov ax, @data ; Initialize data section <br/> mov ds, ax <br/> mov al, a ; Load number1 in al <br/> mov bl, b ; Load number2 in bl <br/> and al, 0fh ; unmask numbers and result in al <br/> and bl, 0fh ; unmask numbers and result in al <br/> add al, bl ; add the numbers in al and bl <br/> cmp al, 09h ; check if no is valid BCD <br/> jb next <br/> add al, 06h ; for invalid BCD add 6 to <br/> ; make it valid <br/> next: mov ch, 02h ; Count of digits to be <br/> ; displayed <br/> mov cl, 04h ; Count to roll by 4 bits <br/> mov bh, al ; Result in reg bh <br/> l2: rol bh, cl ; roll bl so that msb comes <br/> ; to lsb <br/> mov dl, bh ; load dl with data to be <br/> ; displayed <br/> and dl, 0fH ; get only lsb <br/> cmp dl, 09 ; check if digit is 0-9 or <br/> ; letter A-F <br/> jbe l4 <br/> add dl, 07 ; if letter add 37H <br/> ; else only add 30H <br/> l4: add dl, 30H <br/> mov ah, 02 ; Function 2 under INT <br/> ; 21H (Display character) <br/> int 21H <br/> dec ch ; Decrement Count <br/> jnz l2 <br/> mov ah, 4cH ; Terminate Program <br/> int 21H <br/> end <br/></code></span> |
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
Source projectgeek.com