Objective
In this post we will see how to write assembly program to Multiply Two 8 Bit BCD Numbers. Both the numbers will be provided as input to the program which in the end will calculate product. After calculation it will be adjusted before printing it to screen.
Multiple two 8 bit BCD numbers Algorithm
Step I : Initialize the data segment.
Step II : Get the first unpacked BCD number.
Step III : Get the second unpacked BCD number.
Step IV : Multiply the two numbers.
Step V : Adjust result to valid unpacked BCD number in AX.
Step VI : Display the result.
Step VII : Stop.
Program Code
We need to declare two number and load the first number in AL and then second number in BL. Do the multiplication of these numbers and adjust based on unpacked BCD number which is must before printing the result.
1 |
<span style="font-family: arial, helvetica, sans-serif; font-size: 14pt;">.model small<br/><br/>.data<br/><br/>a db 04H<br/><br/>b db 06H<br/><br/>.code<br/><br/>mov ax, @data ; Initialize data section<br/><br/>mov ds, ax<br/><br/>mov ah, 0<br/><br/>mov al, a ; Load number1 in al<br/><br/>mov bl, b ; Load number2 in bl<br/><br/>mul bl ; multiply numbers and result in ax<br/><br/>aam ; adjust result to valid unpacked BCD<br/><br/>mov ch, 04h ; Count of digits to be displayed<br/><br/>mov cl, 04h ; Count to roll by 4 bits<br/><br/>mov bx, ax ; Result in reg bx<br/><br/>rol bx, cl ; roll bl so that msb comes to lsb<br/><br/>mov dl, bl ; load dl with data to be displayed<br/><br/>and dl, 0Fh ; get only lsb<br/><br/>cmp dl, 09 ; check if digit is 0-9 or letter A-F<br/><br/>jbe l4<br/><br/>add dl, 07 ; if letter add 37H else only add 30H<br/><br/>add dl, 30H<br/><br/>mov ah, 02 ; Function 2 under INT 21H (Display character)<br/><br/>int 21H<br/><br/>dec ch ; Decrement Count<br/><br/>jnz l2<br/><br/>mov ah, 4cH ; Terminate Program<br/><br/>int 21H<br/><br/>end<br/></span> |
You can find more assembly language codes on this link. You can run this program using TASM which need to be installed on windows machine. Program running steps are :
C:\programs>tasm mult8bit.asm
Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International
Assembling file: mult8bit.ASM
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 437k
Please leave a comment if you like this post.
Source projectgeek.com