I'm trying to create a print_hex function that converts a hex value in register bx into a character array and I am struggling to realize why is nasm is telling me that I have an invalid effective address. My print_hex function looks like this:
print_hex:
pusha
; shift counter
mov ax, 12
ph_loop:
; if bx is 0 just print the predefined "0000" on hex_buff
test bx, bx
jz ph_loop_end
mov cx, bx
; mask cx to have only the first character
and cx, 0x000F
; use cx as the offset in the table and bring the character into cx (this is where the compile error happens)
mov cx, [hex_table + cx]
; copy into a buffer the character that i just brought (using cl because for some reason if I use cl it copies 2 characters from the table)
mov [hex_buff], cl
shr bx, ax
; decrement counter by 4
sub ax, 4
jmp ph_loop
ph_loop_end:
mov bx, hex_buff
call print_string
popa
ret
Some more info this is being run as a bootsector program. I have read a couple of articles about using lea but I am not sure if I could use it here.