First it rotates the 32-bit value in res
so that the previous 4 most significant bits end up in the 4 least significant bits:
mov eax,res
rol eax, 04h
mov res,eax
For example, if res
held 0x12345678
at the first line, eax
and res
would both hold 0x23456781
after the third line.
It then masks away all but the 4 least significant bits of al
:
and al, 0Fh
If we continue with my example above, al
will now contain 0x01
.
It then adds 7 to al
if al >= 0x0A
(JC
can be viewed as Jump if unsigned less than
), and finally adds '0'
(0x30) to al
:
cmp al, 0Ah
JC d1
add al,07h
d1: add al,30h
If al
originally was in the range 0..9 it will now be in the range 0x30..0x39 (ASCII '0'..'9'
). If it was originally in the range 0x0A..0x0F it will now be in the range 0x41..0x46 (ASCII 'A'..'F'
).
Finally it prints the resulting character using int 21h / ah=02h
(WRITE CHARACTER TO STANDARD OUTPUT
).
It then repeats this 7 more times (i.e. for every hex digit in the 32-bit input number).