Code: Select all
HexToString:
mov di, HexNumberBuffer
xor ah, ah ; zero-out ah so shifiting doesn't cause bits of ah to come into al
push ax ; save AL
shr al, 4 ; Shift AL along 4 bits
add al, 48d ; add 48 onto it
cmp al, 57d ; see if it's > 9
jg .letter
.return:
stosb
pop ax
shl al, 4
shr al, 4
add al, 48d
cmp al, 57d
jg .letter_last_digit
stosb
.quit:
ret
.letter:
add ax, 7d
jmp .return
.letter_last_digit:
add ax, 7d
stosb
jmp .quit
However, if I load AL with 0x2B, I get the string '2B' in my output buffer but if I load al with 0x2b, I get '2b' in the output buffer. The case of the letter(s) in the hex value are reflected in the string!
How is this possible?! Aren't 0x2B and 0x2b stored as the exact same thing?
Someone please point out why this is happening