I just started learning assembly, so this is, without doubt, a stupid question, but I still can't figure it out. I'm trying to write a procedure that would print the given 16-bit word in hex.
I figured that I could divide it into 4-bit chunks by shifting left and right, and then use it as an index to copy symbol constant from prepared table to output variable. Here how my code looks right now:
; Print hex at AX print_hex: pusha mov cx, 0 ; iterator CX = 0 print_hex_loop: mov dx, bx ; DX = symbol index shl dx, cx ; Loose more significant digits << ERROR shr dx, 3 ; Loose less significant digits add dx, HEX_TABLE ; DX = table address add cx, HEX_OUT + 2 ; CX = output address mov byte [cx], [dx] ; HEX_OUT[cx] = HEX_TABLE[dx] << ERROR sub cx, HEX_OUT + 2 ; CX = iterator add cx, 1 ; increase iterator CX cmp cx, 4 ; if iterator CX less then 4 jb print_hex_loop ; repeat loop mov ax, HEX_OUT call print_string_loop popa ret HEX_TABLE: db '0123456789abcdef' HEX_OUT: db '0x0000', 0 However, I get errors that I don't quite understand on shl and mov lines:
utility.asm:23: error: invalid combination of opcode and operands utility.asm:27: error: invalid combination of opcode and operands What am I doing wrong here?
<< ERRORsigns at their ends