为什么我的程序集输出处于字母位置? (1 + 1 = b) [英] Why is my assembly output in letter position? (1+1=b)
问题描述
我正在使用tasm.这是一个简单的程序,可以读取用户的输入并将两个数字加起来.但是,我的输出是根据字母位置显示字母
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
例如3 + 5 = h(8) 我希望它以整数显示.
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
推荐答案
您的输入数字是ASCII字符,因此"1"实际上是31h.因此,当您计算1 + 1时,您将得到31h + 31h = 62h,这是ASCII字符"b".
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’.
要将输入数字转换为等效的整数值,您需要减去"0"(30小时).
To convert your input digits to their equivalent integer values you need to subtract ‘0’ (30h).
相反,要将整数数字输出为ASCII字符,则需要添加"0".
Conversely to output integer digits as ASCII characters you will need to add ‘0’.
这篇关于为什么我的程序集输出处于字母位置? (1 + 1 = b)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!