I made a simple adding calculator in assembly 8086 that when you type an input on your keyboard it adds them up. I can add something like 2+2 and get the right answer but, when I add 9+9 it outputs B
.model small
.data
message db "Enter a number: $"
message2 db 0xA, 0xD, "Enter another number: $" ; 0xA = new line, 0xD = carriage return, 0x24 = '$'
plus db " + $"
equal db " = $"
.code
main proc
mov ax, seg message ; ax = message
mov ds, ax ; dx = ax = message
mov dx, offset message
mov ah, 9h ; output of a string at DS:DX
int 21h
mov ah, 01h ; Read character (stores in al)
int 21h
mov bl, al ; saving our input into bl
mov ax, seg message
mov ds, ax ; dx = ax = message2
mov ds, ax ; dx = ax = message2
mov dx, offset message2
mov ah, 9h ; output of a string at DS:DX
int 21h
mov ah, 1h ; Read character
int 21h
mov cl, al ; stores 2nd input
;mov dl, bl ; print 1st input
;mov ah, 02h ; Write character
;int 21h
; print +
mov ax, seg plus
mov ds, ax
mov dx, offset plus
mov ah, 9h
int 21h
; print 2nd number
mov dl, cl
mov ah, 02h
int 21h
; print =
mov ax, seg equal
mov ds, ax
mov dx, offset equal
mov ah, 9h
int 21h
; This is were its having problems adding
; print sum
sub bl, 48
sub cl, 48
add bl, cl
mov dl, bl
add dl, 48
mov ah, 02h
int 21h
endp
end main
Ive tried debugging it to see what is was doing, it was doing everything right but when it got to the adding part itll say 0x12 instead of 0x9 (when doing 9+9)