Invalid opcode and operand operation

I just started looking into assembly, so this is no doubt a stupid question, but I still can't figure it out. I am trying to write a procedure that will print a given 16 bit word in hexadecimal format.

I figured I could split it into 4-bit chunks by shifting left and right, and then use it as an index to copy the character constant from the prepared table to the output variable. This is what my code looks like 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 am getting errors that I don't quite understand on the 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?

+3


source to share


1 answer


shl dx, cx              ; Loose more significant digits << ERROR

      

It should be cl

, notcx



mov byte [cx], [dx]     ; HEX_OUT[cx] = HEX_TABLE[dx] << ERROR

      

Memory-to-memory operations are usually not supported by the CPU. You have to do this in a two-step operation - load from memory into a register and then save from register to another memory location.
+3


source







All Articles