8086 Program to multiply two 8 bit BCD numbers



ØØ       Explanation :
·            Consider that two unpacked numbers are present in the AL and BL registers. We have to multiply the two numbers. The result is stored in the AX register. The AAM (BCD adjust after Multiply) is used to adjust the product to two unpacked BCD digits in AX.



                        eg.    AL = 0000           0100 = unpacked BCD 4
                                  BL = 0000           0110 = unpacked BCD 6

                        MUL BL       AL ´ BL  Result in AX.
                                                AX = 0000     0000    0001    1000 = 18 H
                        AAM             AX = 0000     0010    0000    0100 = 24   i.e. Unpacked BCD for 24.
ØØ       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.
ØØ       Flowchart : Refer flowchart

ØØ       Program :
.model small
.data                                                      
a db 04H
b db 06H
.code
       mov     ax, @data      ; Initialize data section
       mov     ds, ax
       mov     ah, 0
       mov     al, a              ; Load number1 in al
       mov     bl, b             ; Load number2 in bl
       mul      bl                 ; multiply numbers and result in ax    
       aam                        ; adjust result to valid unpacked BCD
       mov     ch, 04h         ; Count of digits to be displayed
       mov     cl, 04h ; Count to roll by 4 bits
       mov     bx, ax           ; Result in reg bx
l2:    rol       bx, cl            ; roll bl so that msb comes to lsb
       mov     dl, bl            ; 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
ØØ       Result :
C:\programs>tasm mul-bcd8.asm
Turbo Assembler  Version 3.0  Copyright (c) 1988, 1991 Borland International
Assembling file:   mul-bcd8.asm
Passes:            1
Remaining memory:  438k
C:\programs>tlink mul-bcd8
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack
C:\programs>mul-bcd8
0204
C:\programs>