Code: Select all
mov word [reg16], ax ;look at register
push ax
call printreg16
pop ax
hang:
jmp hang
printreg16:
mov di, outstr16
mov ax, [reg16]
mov si, hextable
mov cx, 4 ;loop 4 times
.hexloop:
rol ax, 4 ;leftmost will
mov bx, ax ;become
and bx, 0x0F ;rightmost
mov bl, [si+bx] ;index into hexstr
mov [di], bl
inc di
dec cx
jnz .hexloop
mov [outstr16+4], 0
mov si, outstr16
call print_string
ret
print_string:
lodsb ; grab a byte from SI
or al, al ; logical or al by itself
jz .done ; if the result is 0x00 we are done
mov ah, 0x0E
int 0x10 ; print out the character in al
jmp print_string
.done:
ret
outstr16 rb 5 ;register value string
reg16 dw 0x0000
hextable db '0123456789ABCDEF'