使用汇编语言添加两个数字作为输入

时间:2017-04-29 16:21:39

标签: assembly masm x86-16 dos

我必须编写一个汇编程序,它添加两个作为输入接收的数字然后打印总和。还是很新的,并花了大约15个小时试图解决这个问题,它让我疯狂。我的问题是我相信乘法中的某个地方。当我运行程序时,我得到奇怪的字符作为输出。我知道程序正在从输入和减法工作中正确接收数字。然而,当涉及到倍增时,一切都搞砸了。这也是汇编语言8086.一些帮助将不胜感激!!

这是我的代码

;-----------------------------------------------------
        .model small
;-----------------------------------------------------
        .stack  64
;-----------------------------------------------------  
        .data
PR      DB      'ENTER: ','$'
Num1    Label   Byte
Max1    DB      3 ; need to hit atmost 3 keys when entering- 2 digits and the enter key
Act1    DB      ?
N1      DB      4 DUP ('$')
Num2    Label   Byte
Max2    DB      3 ; need to hit atmost 3 keys when entering- 2 digits and the enter key
Act2    DB      ?
N2      DB      4 DUP ('$')
Res     DB      3 DUP ('$')
;-----------------------------------------------------
        .code
MAIN    proc    FAR
        mov     AX,@data        ; Initialize segment
        mov     DS,AX           ; registers

        call    CLEAR
        call    SET_CURSOR
        call    REQUEST_INPUT
        call    GET_INPUT1
        call    REQUEST_INPUT
        call    GET_INPUT2
        call    SET_CURSOR
        call        Convert1


        mov     AX,4C00h        ; Exit to DOS
        int     21h
MAIN    endp
;-----------------------------------------------------
CLEAR   proc    NEAR
        mov     AX, 0600H
        mov     BH, 71H
        mov     CX, 0000H
        mov     DX, 184FH
        int     10H
        ret
CLEAR   endp

;-----------------------------------------------------
SET_CURSOR      proc    NEAR
        mov     AH, 02H
        mov     BH, 0           ;sets color of backround 
        mov     DH, 12
        mov     DL, 40
        int     10H
        ret
SET_CURSOR      endp
;-----------------------------------------------------
REQUEST_INPUT   proc    NEAR
        mov     AH, 09H
        lea     DX, PR
        int     21H 
        ret
REQUEST_INPUT   endp

;-----------------------------------------------------
GET_INPUT1       proc    NEAR
        mov     AH, 0AH
        lea     DX,Num1
        int     21H
        mov     BH, 00
        mov     BL, Max1
        mov     N1[BX],'$'
        ret
GET_INPUT1       endp
;-----------------------------------------------------
GET_INPUT2      proc    NEAR
        mov     AH, 0AH
        lea     DX,Num2
        int     21H
        mov     BH, 00
        mov     BL, Max2
        mov     N2[BX],'$'
        ret
GET_INPUT2       endp
;-----------------------------------------------------          
Convert1        proc    NEAR
                  mov     BX, 0
                    mov     AH, 00h
                mov     AL, N1[BX]   ; Get a character
                Mov Ax, 10
                Mul AL
                 mov     BX, 1
                    mov     BH, 00h
                mov     BL, N1[BX]   ; Get a character
                Add AL, BL
                mov     BX, 0
                    mov     CH, 00h
                mov     CL, N2[BX]   ; Get a character
                Mov Ax, 10
                Mul CL
                 mov     BX, 1
                    mov     BH, 00h
                mov     DL, N2[BX]   ; Get a character
                Add CL, DL
                Add AL, CL
                Mov Ax, 10
                Div Al
                Mov Res[0], AL
                Add AH, 48
                call SET_CURSOR2 
                Mov Res[1], AH              
                mov     AH,09h
                lea     DX, Res
                int     21H
                ret

Convert1   endp                                 
;-----------------------------------------------------          






            ;formula ()N1[0]-48)*10 + (N1[1]-48)
            ;same for N2
            ;before printing need to divide result of N1+N2 by 10. the quation is the frist character remainder is the second character- quaotiant will be in AL, Remainder in AH
            ;then need to add 48 before putting them into the array Res
            ;To go back Add Al,48-Mov Res[0], AL


;------------------------------------------------------------
                end     MAIN 

0 个答案:

没有答案