Author Topic: Error Message: invalid combination of opcode  (Read 24914 times)

James Dunlap

  • Guest
Error Message: invalid combination of opcode
« on: July 29, 2007, 04:21:14 AM »
I get the error message "invalid combination of opcode and operands" for the lines marked below:

mov     byte_83DB7, al ;ERROR
                 or      ah, ah
                 jnz     short loc_1B005
                 cmp     byte word_83DB4, 3 ;ERROR
                 jb      short loc_1AFF6
                 cmp     al, 22h ; '"'
                 jnb     short loc_1AFFA
                 cmp     al, 20h ; ' '
                 jb      short loc_1AFF6
                 mov     al, 5
                 jmp     short loc_1AFFC

Can anyone tell me why?  Both of the addresses used are in the data segment, which is being pointed to by DS.  I am using "bits 16" as this is a DOS program.  The funny memory locations are due to the fact that this is output from a disassembler.  I am working on a project where I need to figure out the format of some files used by an old game, but they are encoded.

If I change them to indirect like,
                  mov [byte_83DB7], al
then it assembles, but as I understand assembly (and I am a HUGE beginner, other than on the C64 years ago), the [] changes the address into a kind of pointer, so it looks up the contents of the address, then uses that as the location of where to store AL.  Am I way off?

Thanks for any help.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Error Message: invalid combination of opcode
« Reply #1 on: July 29, 2007, 03:33:48 PM »
Off by "one level"... or used to Masm syntax...

An unadorned symbol, in Nasm syntax, means an "immediate". In Masm terms, "offset". You want the square brackets:

mov [byte_83db7], al

In asm, there is no "look up the contents of the address and use that as an address" ("dereferencing a pointer"). We have to do that explicitly:

foo db 42
fooptr dd foo ; (dw for 16-bit code)
...
mov eax, [fooptr]
mov al, [eax]

In Masm, either:

mov myvar, al

or:

mov [myvar], al

are acceptable - and generate exactly the same code. In Nasm, only the second is acceptable. If we see:

mov eax, something

we need to know if it's Masm or Nasm - and if it's Masm, how "something" is declared:

something equ 42

would move the immediate number 42 into eax. If it's:

something dd 0

it moves the *contents" of "something" (0) into eax.  To get the address, you'd need "offset something".

In Nasm, "mov eax, something" is always an immediate - address/offset or other. "Contents" always wants "[]". And *all* of the address goes inside the brackets. Your disassembler may produce something like "es:[foo]" or "es:foo[8]" - in Nasmese, "[es:foo + 8]"...

Hope that helps...

Best,
Frank

James Dunlap

  • Guest
Re: Error Message: invalid combination of opcode
« Reply #2 on: July 29, 2007, 06:46:42 PM »
Thank you.

That most definitely helps.  I am using NASM, and this helps to explain what is happening.

nobody

  • Guest
Re: Error Message: invalid combination of opcode
« Reply #3 on: July 29, 2007, 07:16:17 PM »
> funny memory locations are due to the fact that this is output from a disassembler

A FAULTY disassembler ...

Use NDISASM or DISTORM ;-)