Assembly Program for Multiplying 5 digit numbers


;----------------------------------------------------------------------------   

    PAGE    58,132

;----------------------------------------------------------------------------

;    DISPLAY
;
;    Purpose:
;        to multiply 5 digit number

;----------------------------------------------------------------------------

    TITLE    DISPLAY-multiplication
    .MODEL SMALL
    .286

    .STACK

;----------------------------------------------------------------DATA segment
   
    .DATA
MSG1    DB    "MULTIPLICATION OF 5 DIGIT INTEGERS",0DH,0AH
L_MSG1    EQU    $-MSG1
MSG2    DB    "ENTER FIRST NUMBER:"
L_MSG2    EQU    $-MSG2
NUM1    DB    7 DUP(?)
MSG3    DB    "ENTER SECOND NUMBER:"
L_MSG3    EQU    $-MSG3
NUM2    DB    7 DUP(?)
MSG4    DB    "PRODUCT="
L_MSG4    EQU    $-MSG4
PRO    DB    11 DUP(?)
TOOL    DB    ?

;----------------------------------------------------------------CODE segment

    .CODE
    PAGE

;----------------------------------------------------------------------------

;Procedure: MAIN

MAIN    PROC    FAR
.STARTUP

;displays MSG1------welcome note
    MOV    BX, 0001H
    LEA    DX, MSG1
    MOV    CX, L_MSG1
    MOV    AH, 40H
    INT    21H   
;displays MSG2------asking of operand1       
    MOV    BX, 0001H
    LEA    DX, MSG2
    MOV    CX, L_MSG2
    MOV    AH, 40H
    INT    21H   
;get entry of first number
    MOV     CX,7
    LEA    DX,NUM1
    MOV     AH, 3FH
    MOV    BX, 0000H
    INT    21H
;displays MSG3-------asking of operand2
    MOV    BX, 0001H
    LEA    DX, MSG3
    MOV    CX, L_MSG3
    MOV    AH, 40H
    INT    21H
;get entry of second number
    MOV     CX,7
    LEA    DX,NUM1
    MOV     AH, 3FH
    MOV    BX, 0000H
    INT    21H

;conversion of entries from ASCII to BCD
    LEA    SI, NUM1
    CALL    ASCII_TO_BCD
    LEA    SI, NUM2
    CALL    ASCII_TO_BCD
;to have a space of one line
    MOV    AH,2H
    MOV    DX,0DH
    INT    21H
    MOV    DX,0AH
    INT    21H
;displays MSG4-------display of product
    MOV    BX, 0001H
    LEA    DX, MSG4
    MOV    CX, L_MSG4
    MOV    AH, 40H
    INT    21H
;defining register for multiplication
    LEA    SI,NUM1
    LEA    BX,NUM2
    LEA    DI,PRO
    CALL    MULTIPLICATION

;conversion of product form BCD to ASCII
    CALL    BCD_TO_ASCII

;display product
    LEA    DX,PRO
    MOV    CX,10
    MOV    AH, 40H
    MOV    BX,0001H
    INT    21H

.EXIT
MAIN ENDP

;*******************************PROCEDURES***********************************

;----------------------------------------------------------------------------

;ASCII_TO_BCD
;Purpose:
;    -to convert the entries from ASCII to BCD
;Input:
;    -[SI]
;Output:
;    -[SI]
;Procedures:
;    -

;----------------------------------------------------------------------------

;start of the procedure:ASCII_TO_BCD

ASCII_TO_BCD PROC
   
    PUSHA

TO_BCD:
    MOV    AL,[SI]
    CMP    AL,0DH
    JE    END_BCD
    SUB    AL, 30H
    MOV    [SI], AL
    INC    SI
    JMP    TO_BCD

END_BCD:
    MOV    TOOL,-1
SHIFT:   
    ADD    TOOL,1
    MOV    DL,[SI+6]
    CMP    DL,TOOL
    JE    END_SHIFT
    CMP    TOOL,9
    JL    SHIFT
    MOV    DL,[SI+5]
    MOV    [SI+6],DL
    MOV    DL,[SI+4]
    MOV    [SI+5],DL
    MOV    DL,[SI+3]
    MOV    [SI+4],DL
    MOV    DL,[SI+2]
    MOV    [SI+3],DL
    MOV    DL,[SI+1]
    MOV    [SI+2],DL
    MOV    DL,[SI]
    MOV    [SI+1],DL
    MOV    DL,0
    MOV    [SI],DL
    MOV    COUNT,-1
    JMP    SHIFT

END_SHIFT:   

    POPA
    RET
ASCII_TO_BCD    ENDP

;----------------------------------------------------------------------------
;----------------------------------------------------------------------------

;BCD_TO_ASCII
;Purpose:
;    -to convert the procudt from BCD tO ASCII
;Input:
;    -[SI]
;Output:
;    -[SI]
;Procedures:
;    -

;----------------------------------------------------------------------------

;start of the procedure: BCD_TO_ASCII

BCD_TO_ASCII PROC
    LEA    DI,PRO
   
    PUSHA

TO_ASCII:
    MOV    AL,[DI]
    CMP    AL,0DH
    JE    END_ASCII
    ADD    AL, 30H
    MOV    DI, [AL]
    INC    DI
    JMP    TO_ASCII

END_ASCII:
   
    POPA
    RET
BCD_TO_ASCII ENDP

;-----------------------------------------------------------------------------
;----------------------------------------------------------------------------

;MULTIPLICATION
;Purpose:
;    -to multiply 5 digit numbers
;Input:
;    -
;Output:
;    -[SI]
;Procedures:
;    -

;----------------------------------------------------------------------------

;start of the procedure: MULTIPLICATION

MULTIPLICATION PROC
    PUSHA
   
    ADD    BX, 6
    ADD    SI, 6
    PUSH    SI
    PUSH    BX
   
    MOV     BP,SP
    MOV     AX,0
    ADD    DI,9
    PUSH DI
   
M1:    MOV    AL,00H
    MOV    [DI],AL
    CMP    DI,ODH
    JE    M2
    DEC    DI

M2:    POP    DI

M3:    MOV    SI,[BP+2]
    PUSH    DI

M4:    MOV    AL,[SI]
    MOV    AH,[BX]
    MUL    AH
    ADD    [DI],AL
    MOV    AL,[DI]
    AAM
    MOV    [DI],AL
    DEC    DI
    ADD    [DI],AH
    DEC    SI
    CMP    SI,0DH
    JNE    M4
    DEC    BX
    CMP    BX,0DH
    JNE    M4
   
    POPA
    RET
MULTIPLICATION ENDP
.EXIT
;--------------------------------------------------------------------------
   

   

Share:

2 comments:

  1. Yup. Its for 32bit. But nowadays, compilers does not depend on the OS version. New programs are capable of running it right on 32/64 bit.

    ReplyDelete

Thanks for Suggestion / Comment!

God Bless!

Our Sponsor

Popular Post

Blog Archive