尝试编写汇编代码将三个数字相加

问题描述

我正在尝试编写一个汇编代码,要求用户输入3个数字并将其相加,但是我的以下代码似乎出了点问题,首先,它以ASCII格式显示了结果,并且它没有给我写加结果。

.MODEL SMALL 
.STACK 100H
.DATA
    PROMPT_1 DB 'Enter the First number : $' 
    PROMPT_2 DB 'Enter the Second number : $' 
    PROMPT_3 DB 'Enter the Third number : $' 
    PROMPT_4 DB 'The Sum of three numbers is = $' 
    NUM1 DB ?
    NUM2 DB ?
    NUM3 DB ?
    Sum  DB ?
.CODE

  MAIN PROC 
    MOV AX,@DATA 
    MOV DS,AX ; initialize DS
; display massage and enter the first number and save it in num1 variable
    LEA DX,PROMPT_1 ; load and display the PROMPT_1 
    MOV AH,9
    INT 21H
    MOV AH,1 ; read a character
    INT 21H
    SUB AL,30H ; save First digit in VALUE_1 in ASCII code 
    MOV NUM1,AL
    MOV AH,2 ; carriage return
    MOV DL,0DH
    INT 21H
    MOV DL,0AH ; line feed
    INT 21H
; display massage and enter the Second number and save it in num2 variable
    LEA DX,PROMPT_2 ; load and display the PROMPT_2 
    MOV AH,30H ; save First digit in NUM1 in ASCII code 
    MOV NUM2,0AH ; line feed 
    INT 21H
; display massage and enter the third number and save it in num3 variable
    LEA DX,PROMPT_3 ; load and display the PROMPT_3
    MOV AH,30H ; save First digit in NUM3 in ASCII code 
    MOV NUM3,0AH ; line feed
    INT 21H
; Print massage in the prompt_4 on the screen 
    LEA DX,PROMPT_4 ; load and display thePROMPT_4 
    MOV AH,9 
    INT 21H
; Calculate the sum of NUM1+NUM2+NUM3 
    MOV AL,NUM1
    ADD AL,NUM2
    ADD AL,NUM3
    
    MOV AH,0

    Add AL,30H ; convert ASCII to DECIMAL code 
    MOV AH,2 ; display the character
    MOV DL,AL
    INT 21H
    
    MOV AH,4CH
    INT 21H
  MAIN ENDP 
  END MAIN

如果我运行此代码,结果将是 三个数字的总和是=>

(例如,如果我输入3 4 5)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...