简体   繁体   中英

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. 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:

在此处输入图片说明

Your program successfully creates a packed BCD from the 2 inputs.
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.

; 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:

The code that you've posted MOV AH,1 INT 21H can not have produced this output! Maybe you wrote mov ah,9 in the code that produced the screenshot?

Also the screenshot is missing a space character between the "R" and the ":".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM