Q:

Hex to Ascii Conversion in x86 alp

I am currently learning alp(x86).I recently stumbled upon a program which is used to display characters stored in array which are ,basically in hex form.in order to display them we should convert them into ascii and then display them.
    ;display procedure for 64bit
     display:
    mov rsi,char_answer+15
    mov rcx,16
    cnt:    mov rdx,0
            mov rbx,16h
            div rbx
            cmp dl,09h
            jbe add30
            add dl,07h
    add30:    add dl,30h
            mov [rsi],dl
            dec rsi
            dec rcx
            jnz cnt
    scall 1,1,char_answer,16
    ret

so in above code i could not get why we are comparing with 09h and then adding 30h or 07h.
Thankyou.

A:

In ASCII and its successors, the decimal digits are mapped in the range of 0x30..0x39, and the first six letters, which function as hexadecimal numbers ten to fifteen, are mapped in the range of 0x41..0x46.  Once the procedure has extracted a single hex digit, in order to convert it into the ASCII code representing its value, it needs to add 0x30 if the digit is in the range of 0..9, or 0x41-0x0A = 0x37 if the digit is in the range of A..F.
This is a common idiom in assembly languages.

