39 lines
465 B
Plaintext
39 lines
465 B
Plaintext
;Converts a byte in AH to a hex string at DI.
|
|
|
|
byte2hex:
|
|
|
|
;Store the initial registers in the stack
|
|
pusha
|
|
|
|
;Set a key for the hex digits
|
|
mov si, .key
|
|
|
|
;Set a counter for the two hex digits
|
|
mov cx, 0x2
|
|
|
|
.loop:
|
|
|
|
;Read a nibble
|
|
rol ax, 0x4
|
|
mov bx, ax
|
|
|
|
;Convert the nibble to a hex digit
|
|
and bx, 0xf
|
|
mov bl, [si + bx]
|
|
|
|
;Store the hex digit
|
|
mov [di], bl
|
|
|
|
;Repeat
|
|
inc di
|
|
dec cx
|
|
jnz .loop
|
|
|
|
;Load the initial registers from the stack
|
|
popa
|
|
|
|
ret
|
|
|
|
.key:
|
|
db "0123456789abcdef"
|