Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
.model small
.stack 100h
.data
msg db 'enter 1st number:','$'
msg1 db 'enter 2nd number:','$'
msg2 db 'sum is:','$'
.code
main proc
mov ax,@data
mov ds,ax
mov ah,09h
lea dx,msg
int 21h
mov ah,01h
int 21h
mov bl,al
mov dx,0ah
mov dx,0dh
mov ah,09h
lea dx,msg1
int 21h
mov ah,01h
int 21h

mov cl,al

add bl,cl
sub bl,30h                    ; why subtraction gives the right answer?
mov ah,09h
lea dx,msg2
int 21h
mov ah,02h
mov dl,bl
int 21h
mov ah,4ch
int 21h
main endp
end main
Posted
Updated 24-Sep-14 0:31am
v2

1 solution

Because 30 hex is the code for a '0' character - so it converts '1' to a number one, '2' to a number two and so forth. Do note that this won't help with hex values 'A' to 'F' - it will not give you the right value at all.

Google ASCII table for a better idea how characters are different from numbers and what you might need to do to cope with 'A' to 'Z'...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900