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
Solution 1:
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’.