I am trying to write a library function in 8086 assembly that will dump the contents of the registers as hex values, but my code doesn't appear to be working right and I don't know why. The basic strategy is to shift the register to be dumped right by 12, 8, 4 and 0 and use the value in the low byte of the register to index into a table of hex characters. The code works for the first digit, but it prints nothing (or an invisible character) for the second digit. Here's my code:
hex_tbl:
db '0123456789ABCDEF'
print_tbl:
mov bx, hex_tbl
mov dx, 0x9FFF ; Value to be printed
push dx
shr dx, 12
add bl, dl
mov ax, [bx]
sub bl, dl
call display_letter
pop dx
shr dx, 8
add bl, dl
mov ax, [bx]
sub bl, dl
call display_letter
ret
; Display letter in AL (ASCII code)
display_letter:
push ax
push bx
push cx
push dx
push si
push di
mov ah, 0x0e ; Load AH with code for terminal output
mov bx, 0x000f ; Load BH page zero and BL color (graphic mode)
int 0x10 ; Call the BIOS for displaying one letter
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret ; Returns to caller