Objective
In this post we will assembly language code for Add Two 16 Bit BCD Numbers Code which we will be running using TASM on windows. So First we are going to initialize memory for storing two numbers which will be loaded into AX and BX registers respectively.
Add Two 16 Bit BCD Numbers Algorithm
Step I : Initialize the data memory.
Step II : Load the first number into AX register.
Step III : Load the second number into BX register.
Step IV : Add two lower digits.
Step V : Adjust result to valid BCD number.
Step VI : Store the result in BL.
Step VII : Add the two upper digits with carry.
Step VIII : Adjust result to valid BCD number.
Step IX : Store the result in BH.
Step X : Display the result.
Step XI : Stop.
16 Bit BCD Numbers Program
1 |
<span style="font-size: 14pt; font-family: arial, helvetica, sans-serif;"> .model small <br/> .data <br/> a dw 3629H <br/> b dw 4738H <br/> .code <br/> mov ax, @data ; Initialize data section <br/> mov ds, ax <br/> mov ax, a ; Load number1 in ax <br/> mov bx, b ; Load number2 in bx <br/> add al, bl ; add lower two digits. Result in al <br/> daa ; adjust result to valid bcd <br/> mov bl, al ; store result in bl <br/> adc ah, bh ; add upper two digits. Result in ah <br/> mov al, ah ; al=ah as daa works on al only <br/> daa ; adjust result to valid BCD <br/> mov bh, al ; store result in bh <br/> mov ch, 04h ; Count of digits to be displayed <br/> mov cl, 04h ; Count to roll by 4 bits <br/> rol bx, cl ; roll bl so that msb comes to lsb <br/> mov dl, bl ; load dl with data to be displayed <br/> and dl, 0fH ; get only lsb <br/> cmp dl, 09 ; check if digit is 0-9 or letter A-F <br/> jbe l4 <br/> add dl, 07 ; if letter add 37H else only add 30H <br/> add dl, 30H <br/> mov ah, 02 ; Function 2 under INT 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/></span> |
Find more assembly language codes here.
Source projectgeek.com