Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

dos - Why is my assembly output in letter position? (1+1=b)

I am using tasm. It is a simple program that reads the inputs from user and add the two numbers up. However, my output is displaying letters according to their letter position

For example, 3+5=h (8) I want it to display in integer number.

.model small 
.stack 100h
.data 
input   db  13,10,"Enter a number : ","$"
output  db  13,10,"The sum is ","$"

.code
main    proc

mov ax,@data
mov ds,ax

;INPUT 1
mov ah,9
mov dx, offset input 
int 21h
mov ah,1
int 21h
mov bl,al

;INPUT 2
mov ah,9
mov dx, offset input
int 21h
mov ah,1
int 21h
add bl,al

;OUTPUT DISPLAY
mov ah,9
mov dx,offset output
int 21h

mov ah,2
mov dl,bl
int 21h

;END
mov ax,4c00h
int 21h
main    endp
end main
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your input digits are ASCII characters, so ‘1’ is actually 31h, for example. So when you calculate 1+1 your are getting 31h+31h=62h which is the ASCII character ‘b’.

To convert your input digits to their equivalent integer values you need to subtract ‘0’ (30h).

Conversely to output integer digits as ASCII characters you will need to add ‘0’.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...