2021-06-10 15:16:14 +00:00
|
|
|
;Converts a byte in AL to a hex string at DI.
|
2021-05-30 16:12:19 +00:00
|
|
|
|
2021-06-06 16:56:54 +00:00
|
|
|
byte2hex:
|
2021-05-30 16:12:19 +00:00
|
|
|
|
2021-06-06 08:18:15 +00:00
|
|
|
;Store the initial registers in the stack
|
2021-06-10 15:16:14 +00:00
|
|
|
push si
|
|
|
|
push ax
|
|
|
|
push bx
|
|
|
|
push cx
|
|
|
|
|
|
|
|
;Move the byte to AH
|
|
|
|
mov ah, al
|
2021-06-06 08:18:15 +00:00
|
|
|
|
2021-05-30 16:12:19 +00:00
|
|
|
;Set a key for the hex digits
|
|
|
|
mov si, .key
|
|
|
|
|
2021-06-08 12:25:17 +00:00
|
|
|
;Set a counter for the two hex digits
|
2021-05-30 16:12:19 +00:00
|
|
|
mov cx, 0x2
|
|
|
|
|
|
|
|
.loop:
|
|
|
|
|
2021-06-08 12:25:17 +00:00
|
|
|
;Read a nibble
|
2021-06-10 15:16:14 +00:00
|
|
|
rol ax, 0x1
|
|
|
|
rol ax, 0x1
|
|
|
|
rol ax, 0x1
|
|
|
|
rol ax, 0x1
|
2021-05-30 16:12:19 +00:00
|
|
|
mov bx, ax
|
|
|
|
|
2021-06-08 12:25:17 +00:00
|
|
|
;Convert the nibble to a hex digit
|
2021-05-30 16:12:19 +00:00
|
|
|
and bx, 0xf
|
|
|
|
mov bl, [si + bx]
|
|
|
|
|
|
|
|
;Store the hex digit
|
|
|
|
mov [di], bl
|
|
|
|
|
|
|
|
;Repeat
|
|
|
|
inc di
|
|
|
|
dec cx
|
|
|
|
jnz .loop
|
|
|
|
|
2021-06-06 08:18:15 +00:00
|
|
|
;Load the initial registers from the stack
|
2021-06-10 15:16:14 +00:00
|
|
|
pop cx
|
|
|
|
pop bx
|
|
|
|
pop ax
|
|
|
|
pop si
|
2021-06-06 08:18:15 +00:00
|
|
|
|
2021-05-30 16:12:19 +00:00
|
|
|
ret
|
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
.key db "0123456789abcdef"
|