汇总得到输入的总和

时间:2015-07-17 12:44:16

标签: assembly sum dos x86-16

我在装配中遇到问题,我无法得到2个输入数字的总和和乘积。我仍在努力获得总和,但似乎我无法得到它。我正在使用emu8086。你能帮我修一下这些代码吗?我还不能得到他们的产品。我是新手。感谢。

.MODEL SMALL
.STACK 1000
.DATA
MSGA DB 13,10,"Input first number: ","$"
MSGB DB 13,10,"Input second number:","$"
MSGC DB 13,10,"The sum is: ","$"
NUM1 db ?
NUM2 db ?
NUM3 db ?
.CODE
MAIN PROC NEAR
MOV AX, @DATA
MOV DS, AX
LEA DX, MSGA
MOV AH, 09h
INT 21h
MOV AH, 01
INT 21H
SUB AL, '0'
MOV BL, AL
MOV AH, 01
INT 21H
SUB AL, '0'
MOV CL, AL
LEA DX, MSGB
MOV AH, 09h
INT 21h
MOV AH, 01
INT 21H
SUB AL, '0'
MOV DL, AL
MOV AH, 01
INT 21H
SUB AL, '0'
MOV DH, AL
MOV AL, CL
MOV AH, BL
ADD AL, DH
AAA
ADD AH, DL
MOV NUM1, AL
ADD NUM1, '0'
CMP AH, 9
JLE NOT_3DIGIT
IS_3DIGIT:
MOV AL, AH   
SUB AH, AH   
ADD AL, 0    
AAA          
ADD AH, 0    
MOV NUM2, AL
MOV NUM3, AH
ADD NUM2, '0'
ADD NUM3, '0'
LEA DX, MSGC
MOV AH, 09h
INT 21h
MOV DL, NUM3
MOV AH, 02H
INT 21h
MOV DL, NUM2
MOV AH, 02H
INT 21h   
JMP PRINT_LASTDIGIT  


NOT_3DIGIT:
MOV NUM2, AH
ADD NUM2, '0'
LEA DX, MSGC
MOV AH, 09h
INT 21h
MOV DL, NUM2
MOV AH, 02H
INT 21h   


PRINT_LASTDIGIT:
MOV DL, NUM1
MOV AH, 02H
INT 21h 


EXIT:
MOV AH, 4Ch
INT 21h 
MAIN ENDP
END MAIN

1 个答案:

答案 0 :(得分:0)

您正在使用2位数输入,因此在乘法后,您希望将答案转换回原来的[decimal]形式以进行显示。 这可以通过将其除以10然后相应地显示系数和余数来完成,这是乘法的代码,首先取2位数字然后乘以另一个单位数, 但这只是为了给你一个想法:

.model small
.stack
.data
msg1 db 10,13,'First Value:','$';
msg2 db 10,13,'Second Value:','$'; 
msg3 db 10,13,'multiplication:','$';
second db ?
temp db ?
num1 db ?
num2 db ?
a db 10 

.code
main proc
mov ax,@data
mov ds,ax 
mov ah,09h
lea dx,msg1
int 21h
mov ah,01h
int 21h
sub al,30h
mul a
mov temp,al
mov ah,01h
int 21h
sub al,30h
add temp,al
mov [bx],al
mov ah,09h
lea dx,msg2
int 21h
mov ah,01h
int 21h
mov second,al
sub second,30h
mov ax,00h
mov al,temp
mul second
div a
mov num1,al
mov num2,ah
add num1,30h
add num2,30h 
mov ah,09h
lea dx,msg3
int 21h
mov ah,02h
mov dl,num1
int 21h
mov ah,02h
mov dl,num2
int 21h
mov al,0
inc bx
dec cx
mov ah,4ch
int 21h
main endp
end main

我希望它有所帮助!