News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Word register cannot be first operand in MASM

Started by etairi, December 31, 2017, 05:11:44 AM

Previous topic - Next topic

etairi

I have the following MASM code segment which causes an error:

    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.

aw27

Instead of rax, use mm0 or xmm0 (they are not word registers)

etairi

Quote from: aw27 on December 31, 2017, 05:46:18 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.

aw27

Quote from: etairi on December 31, 2017, 05:49:53 AM
Quote from: aw27 on December 31, 2017, 05:46:18 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

Quote from: aw27 on December 31, 2017, 05:54:04 AMmovq 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:
mov al, 0FEh
movsx rax, al


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

This sets rax to zero (the high dword of reg64 gets cleared by a mov reg32):
and eax, 0

But attention, this will not set rax to -1:
or eax, -1

etairi

Quote from: jj2007 on December 31, 2017, 06:35:27 AM
Quote from: aw27 on December 31, 2017, 05:54:04 AMmovq 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:
mov al, 0FEh
movsx rax, al


And this produces the same result for x2_1 but is 3 bytes shorter:
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

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

Quote from: jj2007 on December 31, 2017, 06:35:27 AM
Quote from: aw27 on December 31, 2017, 05:54:04 AMmovq 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:
mov al, 0FEh
movsx rax, al


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

This sets rax to zero (the high dword of reg64 gets cleared by a mov reg32):
and eax, 0

But attention, this will not set rax to -1:
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.