1

So my doubt is why are we using ADD AL,07H if AL contains something greater than 10? What's the explanation for ADD AL,07. Here is the code.

MOV AH,01H  ;TAKE INPUT 
INT 21H

MOV BL,AL   ; SAVE VALUE OF AL, SO THAT IT CAN BE USED LATER
MOV CL,04H  
SHR AL,CL   ;SHIFT AL TOWARDS RIGHT BY 4 BITS

CMP AL,0AH  ;COMPARE IF AL HAS 10
JB DIGIT
ADD AL,07H
DIGIT: 
    ADD AL,30H  ;Add 30 to make HEX equivalent ASCII code
    MOV RES,AL

    AND BL,0FH
    CMP BL,0AH
    JB DIGIT1
    ADD BL,7H

DIGIT1: 
    ADD BL,30H
    MOV RES+1,BL

LEA DX,RES    ; display the result
    MOV AH,9
    INT 21H

Thank you.

Khacho
  • 199
  • 3
  • 16

1 Answers1

2

Your program does (2 times in a row) the conversion of a 4-bit value into a displayable character. Results will obey the following table:

 0 -> "0"   "0" has ASCII 48 =  0 + 48
 1 -> "1"
 2 -> "2"
 3 -> "3"
 4 -> "4"
 5 -> "5"
 6 -> "6"
 7 -> "7"
 8 -> "8"
 9 -> "9"   "9" has ASCII 57 =  9 + 48
10 -> "A"   "A" has ASCII 65 = 10 + 48 + 7
11 -> "B"
12 -> "C"
13 -> "D"
14 -> "E"
15 -> "F"   "F" has ASCII 70 = 15 + 48 + 7

From this table you can see that the ASCII's don't nicely follow each other when changing from 9 to 10. To compensate for this 7 character gap (it holds the characters :;<=>?@) you used the instructions add al,7 and add bl,7

Sep Roland
  • 33,889
  • 7
  • 43
  • 76