I have a procedure which takes a 2-digit input from the user but I don't understand why a jump is made to JUMP01 if AL <= 9 and otherwise 7 is subtracted
INPUT PROC NEAR
MOV AH,01
INT 21H
SUB AL,30H
CMP AL,09
JBE JUMP01
SUB AL,07H
JUMP01:
MOV DL,AL
SHL DX,4
MOV AH,01
INT 21H
SUB AL,30H
CMP AL,09
JBE JUMP02
SUB AL,07H
JUMP02:
ADD DL,AL
RET
INPUT ENDP
You don't need to worry, this code just reads hex,assumes capital Letters and does not check about any other chars typed.
It first subtracts '0', so in case of a digit you will have a result le 9.
If not, it assumes you typed 'A'..'F', (0x41..0x46),and therefore subtracts 7 to get the correct result 0x0a..0x0f
This code is reading a 2 digit number in hexadecimal. The reason for the subtraction is that the letters
A
throughF
should be mapped to the range10
through15
(decimal). The ascii code ofA
is 65 which is reduced by48
(thesub al, 30h
) leaving 17, and to get to10
from there it has to be reduced by a further7
. This works for the other letters too.