[英]Assembly emu8086 - How to print the two added numbers?
I am trying to print the 2 digits I inputted but I am having trouble in printing it.我正在尝试打印我输入的 2 位数字,但在打印时遇到问题。 Here's my progress:这是我的进展:
DATA SEGMENT
MSG1 DB "ENTER NUMBER : $"
DIGIT1 DB ?
DIGIT2 DB ?
BCD DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT1,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV DIGIT2,AL
MOV AH,DIGIT1
MOV AL,DIGIT2
MOV CL,4
ROL AH,CL
ADD AL,AH
MOV BCD,AL
MOV AH,1
INT 21H
CODE ENDS
END START
My code can accept 2 digit inputs but it cannot print the inputted 2 added digits and it prints Enter Number:我的代码可以接受 2 位数字输入,但无法打印输入的 2 位添加数字,并且会打印 Enter Number:
Your program successfully creates a packed BCD from the 2 inputs.您的程序成功地从 2 个输入创建了一个打包的 BCD 。
To print the result back to the screen you first take apart what you have put together and then convert the digits into characters that DOS can output.要将结果打印回屏幕,您首先要拆开您放在一起的内容,然后将数字转换为 DOS 可以输出的字符。
; Display the tens:
mov dl, BCD
mov cl, 4
shr dl, cl ; Moves the "tens" from high nibble to low nibble, throwing out the "ones"
or dl, '0' ; Converts from digit value [0,9] to digit character ['0'-'9']; adds 48
mov ah, 02h ; DOS.PrintCharacter
int 21h
; Display the ones:
mov dl, BCD
and dl, 15 ; Only keeps the "ones"
or dl, '0' ; Converts from digit value [0,9] to digit character ['0','9']; adds 48
mov ah, 02h ; DOS.PrintCharacter
int 21h
My code can accept 2 digit inputs but it cannot print the inputted 2 added digits and it prints Enter Number:我的代码可以接受 2 位数字输入,但无法打印输入的 2 位添加数字,并且会打印 Enter Number:
The code that you've posted MOV AH,1
INT 21H
can not have produced this output!您发布的MOV AH,1
INT 21H
代码无法产生此输出! Maybe you wrote mov ah,9
in the code that produced the screenshot?也许您在生成屏幕截图的代码中编写了mov ah,9
?
Also the screenshot is missing a space character between the "R" and the ":".此外,屏幕截图在“R”和“:”之间缺少空格字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.