[英]Assembly emu8086 - How to print the two added numbers?
我正在嘗試打印我輸入的 2 位數字,但在打印時遇到問題。 這是我的進展:
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
我的代碼可以接受 2 位數字輸入,但無法打印輸入的 2 位添加數字,並且會打印 Enter Number:
您的程序成功地從 2 個輸入創建了一個打包的 BCD 。
要將結果打印回屏幕,您首先要拆開您放在一起的內容,然后將數字轉換為 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
我的代碼可以接受 2 位數字輸入,但無法打印輸入的 2 位添加數字,並且會打印 Enter Number:
您發布的MOV AH,1
INT 21H
代碼無法產生此輸出! 也許您在生成屏幕截圖的代碼中編寫了mov ah,9
?
此外,屏幕截圖在“R”和“:”之間缺少空格字符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.