-4

I have a variable called char that is supposed to change his value to a keyboard key when I press that key. I visited How to change the value of a variable in assembly and it said for I to use mov char, key_value. The problem is that I got terminal.asm:126: error: invalid combination of opcode and operands . Searching for the solution online I saw that is necessary to put brackets [ ]. I tried that and the same error occurred.

Here it is a part of my file:

printChar:

    mov edx, char;

    loop5_terminal:
    mov al, [edx];
    mov byte [edi], al;
    inc edi;
    inc edi;
    inc edx;
    inc ebx
    call cursor_terminal
    cmp byte[edx],0;
    jne loop5_terminal;

    jne l2_terminal
l2_terminal:

    cmp al , 0x03      ; Checks for key 2 input

    mov char, [two]
    je printChar
    

Thanks.

zx485
  • 28,498
  • 28
  • 50
  • 59
Lixt
  • 201
  • 4
  • 19
  • In most assembly dialects you do not need to finish a line with a semicolon. A leading semicolon merely indicates the start of a comment. – zx485 Dec 05 '21 at 22:01
  • This is not a complete example. In particular, it doesn't include the definitions of `char` and `two`, which are necessary for us to help. – prl Dec 05 '21 at 22:04
  • 1
    Which line is the error occuring on? Show your full code. – user1280483 Dec 05 '21 at 22:05
  • Nowhere in the linked question or answer do I see any suggestion to use `mov char, key_value`. (Which is a good thing because that wouldn't be valid unless `char` was defined as a macro that expands to different text, like a register name or an addressing mode including square brackets. Because `mov char, whatever` would be like `123 = foo` in C, trying to assign to a constant.) – Peter Cordes Dec 06 '21 at 00:22

1 Answers1

0

The error you get is most likely due to the line

mov char, [two]

which contains two memory operands, namely char and two. This is not possible, because the x86 architecture does not support two memory operands in one instruction.

You'd have to split that "instruction" into two separate (valid) instructions like

mov al, BYTE [two]
mov BYTE [char], al

if you'd use a BYTE sized instruction.

zx485
  • 28,498
  • 28
  • 50
  • 59
  • At least, if OP meant `mov [char], [two]`- `mov char, [two]` is invalid syntax because `char` is a constant memory address. – user1280483 Dec 05 '21 at 22:09
  • If `char` would be a constant, the instruction `mov char, [two]` would be impossible, because there is no sense in moving a value to a constant. – zx485 Dec 05 '21 at 22:14
  • My guess is that `two` is a constant, but that's why I asked for more information before writing an answer. – prl Dec 05 '21 at 23:29
  • Unless `char` is a `%define` macro for something like `[edx]` or `[symbol`], `char` isn't a memory operand; it's an immediate in NASM syntax. (So you definitely can't ever `mov` *to* it, even with a register source). The problem would be two memory operands if both had `[]`. – Peter Cordes Dec 06 '21 at 02:53
  • Because my answer obviously doesn't cover all aspects that need to be addressed in answering this question, I leave it here until tomorrow as basis for someone writing a complete (_reads better_) answer. – zx485 Dec 06 '21 at 03:27