Author Topic: Word register cannot be first operand in MASM  (Read 653 times)

etairi

  • Regular Member
  • *
  • Posts: 10
Word register cannot be first operand in MASM
« on: December 31, 2017, 05:11:44 AM »
I have the following MASM code segment which causes an error:

Code: [Select]
    x2_0  equ 0FFFFFFFFFFFFFFFEh
    x2_1  equ 0FFFFFFFFFFFFFFFFh
   
      movq   rax, x2_0
      sub    rbx, rax
      movq   rax, x2_1
      sbb    r9, rax
      sbb    r10, rax
      sbb    r11, rax
      sbb    r12, rax
The `x2_0` and `x2_1` are defined at the top of the file under `.const`, and the assembly code is part of a function, though, I just put a segment here, as it is where I get the error. I get the error shown below in `movq rax, x2_0` and `movq rax, x2_1` lines:

>  error A2150:word register cannot be first operand

If I change the `movq` to `mov` the error disappears, but I fail to grasp the significance of this error and what it wants to tell me.

AW

  • Member
  • *****
  • Posts: 1215
  • Let's Make ASM Great Again!
Re: Word register cannot be first operand in MASM
« Reply #1 on: December 31, 2017, 05:46:18 AM »
Instead of rax, use mm0 or xmm0 (they are not word registers)

etairi

  • Regular Member
  • *
  • Posts: 10
Re: Word register cannot be first operand in MASM
« Reply #2 on: December 31, 2017, 05:49:53 AM »
Instead of rax, use mm0 or xmm0 (they are not word registers)

I have used only general purpose registers in my code, that's why wanted to keep using them. But, still don't know why the error is appearing. Under Linux it works fine, but using MASM I get that error.

AW

  • Member
  • *****
  • Posts: 1215
  • Let's Make ASM Great Again!
Re: Word register cannot be first operand in MASM
« Reply #3 on: December 31, 2017, 05:54:04 AM »
Instead of rax, use mm0 or xmm0 (they are not word registers)

I have used only general purpose registers in my code, that's why wanted to keep using them. But, still don't know why the error is appearing. Under Linux it works fine, but using MASM I get that error.

I am sure it works fine when you use GAS. But GAS appends sufixes to the Intel instructions to make it easier for people to deal with the complexity of ASM.  :dazzled:
movq in Intel syntax is an instruction, in GAS it is mov expecting a qword

jj2007

  • Member
  • *****
  • Posts: 8352
  • Assembler is fun ;-)
    • MasmBasic
Re: Word register cannot be first operand in MASM
« Reply #4 on: December 31, 2017, 06:35:27 AM »
movq in Intel syntax is an instruction

More precisely, it is an instruction that expects a qword source, but that source can NOT be an immediate.
But the simple mov rax, immediate works.

Btw this produces your desired result with x2_0 but is one byte shorter:
Code: [Select]
mov al, 0FEh
movsx rax, al

And this produces the same result for x2_1 but is 3 bytes shorter:
Code: [Select]
or rax, -1
This sets rax to zero (the high dword of reg64 gets cleared by a mov reg32):
Code: [Select]
and eax, 0
But attention, this will not set rax to -1:
Code: [Select]
or eax, -1

etairi

  • Regular Member
  • *
  • Posts: 10
Re: Word register cannot be first operand in MASM
« Reply #5 on: December 31, 2017, 06:39:39 AM »
movq in Intel syntax is an instruction

More precisely, it is an instruction that expects a qword source, but that source can NOT be an immediate.
But the simple mov rax, immediate works.

Btw this produces your desired result with x2_0 but is one byte shorter:
Code: [Select]
mov al, 0FEh
movsx rax, al

And this produces the same result for x2_1 but is 3 bytes shorter:
Code: [Select]
or rax, -1

Thanks for the explanation. You mentioned Intel syntax. In my GAS code at the top I have `.intel_syntax noprefix `. Does MASM has something similar, or there is no need for it in MASM?

jj2007

  • Member
  • *****
  • Posts: 8352
  • Assembler is fun ;-)
    • MasmBasic
Re: Word register cannot be first operand in MASM
« Reply #6 on: December 31, 2017, 06:43:29 AM »
There is no need for that in Masm. Generally, its syntax is simple. For example:

.if somevar==123   instead of .if [somevar]==123 or .if ([somevar]==123)

.if eax  instead of .if (eax) or .if (eax!=0)

.if !eax instead of .if (eax==0)

etairi

  • Regular Member
  • *
  • Posts: 10
Re: Word register cannot be first operand in MASM
« Reply #7 on: December 31, 2017, 08:41:50 AM »
movq in Intel syntax is an instruction

More precisely, it is an instruction that expects a qword source, but that source can NOT be an immediate.
But the simple mov rax, immediate works.

Btw this produces your desired result with x2_0 but is one byte shorter:
Code: [Select]
mov al, 0FEh
movsx rax, al

And this produces the same result for x2_1 but is 3 bytes shorter:
Code: [Select]
or rax, -1
This sets rax to zero (the high dword of reg64 gets cleared by a mov reg32):
Code: [Select]
and eax, 0
But attention, this will not set rax to -1:
Code: [Select]
or eax, -1

Thanks for the helpful tips. But, it's not just those values, I have many other values too. I just wanted to make sure that using `mov` instead of `movq` is the right choice for MASM, as it removes the errors, but functionality-wise, I was wondering whether it is the right thing to do.