I have a code to make a sum in assembler and it works fine, but I don't understand why it is necessary to make an adjustment to the characters, I have only been able to observe that if I don't make the adjustment when printing the result, a character is displayed that does not correspond to a number.
When I read a character I subtract 30H.
;read number1
MOV AH, 01H
INT 21H
;adjustment
SUB AL, 30H
MOV number1, AL
After doing the sum, add 30H.
ADD AL, number1
;Adjustment
ADD AL, 30H
MOV result, AL
What you are reading is not an integer, it is a character. In ASCII, the character
'0'
is at position 48, or 30H. So to convert a character corresponding to a decimal digit (characters between 48 and 57) to a decimal digit, 48 is subtracted from it.As you can imagine, this returns garbage if you type a letter instead of a number.
You add
0x30
it because you set the integer value to be displayed on the screen as a character value.