2

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
Paul R
  • 208,748
  • 37
  • 389
  • 560
hen
  • 95
  • 1
  • 6
  • Please don’t change the code in the question - it invalidates people’s answers and makes the question less useful for future readers. I’ve rolled back the edit. – Paul R Jul 10 '20 at 06:57
  • 2
    Related: [Why won't the program print the sum of the array?](https://stackoverflow.com/q/53252525) has some example code, specifically `sub al, '0'` to turn an ASCII digit into an integer (assuming it actually *is* a digit) – Peter Cordes Jul 10 '20 at 08:05

1 Answers1

3

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

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • AH tht makes sense! So i just add sub al,30h? I edited my post, if it is alright for you to look through? But my output now is giving me a weird symbol. (A heart shape in dosbox) – hen Jul 10 '20 at 06:50
  • 1
    Re-read my answer above - you need to *subtract* 30h from your input digits and then *add* 30h when you want to output the result. – Paul R Jul 10 '20 at 06:54