News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

QWORD issue

Started by cozofdeath, October 14, 2011, 01:47:45 AM

Previous topic - Next topic

cozofdeath

I'm sorry but I just cannot find the answer to this. I'm simple trying to use the qword (dq) type to declare a variable. But masm will allow the declaration but not the initialization. It keeps spitting out:  "error A2070: invalid instruction operands". For example,

.data?
qwAge    QWORD    ?

.code
mov qwAge, 0


But if I use the data type "LONG" it seems to work. Is qword and long the same size? And why isn't Masm supporting this? I tried using ml64 but it thinks almost every line of code is an error. Thanks for any help!

dedndave

you can override the operand size with "ptr"
        mov dword ptr qwAge,eax   ;initialize the low dword
        mov dword ptr qwAge+4,edx ;initialize the high dword


i dunno who that variable is for, but they must be pretty old   :P

dedndave

another way to go is to split it up
        .DATA?

qwAge   LABEL   QWORD
dwAgeLo dd ?
dwAgeHi dd ?


now, you can access it as a qword with qwAge
or seperate dwords as dwAgeLo and dwAgeHi

jj2007

You cannot move a qword into a reg32, but you can use the FPU or an xmm reg instead:

include \masm32\MasmBasic\MasmBasic.inc   ; download
MyQ   dq 123456789012345678
   Init
   
movq xmm0, MyQ
   fild MyQ
   Print Str$("FPU, ST0=\t%i\n", ST(0))
   Inkey Str$("Xmm0=    \t%i", xmm0)
   Exit
end start


FPU, ST0=       123456789012345678
Xmm0=           123456789012345678

cozofdeath

Thanks dedndave! That was quick. I can't get over how I can't use it like a normal variable. That kinda sucks. Everything has gone smooth until I tried to fill a QWORD in a structure in an accompanied .inc file. It seemed there was no way to fill it until you helped me. I never had to mess with qwords before. :cheekygreen: Thanks again!

cozofdeath

Ahhh...jj2007 :U That seems like a creative way to do it as well. I would have never dreamed up something like that.  :dance: Thanks

MichaelW

For what it's worth, if you put the variable in the initialized data section you can initialize it like this:

.data
    qwAge QWORD 0ffffffffffffffffh


eschew obfuscation

GregL

#7
cozofdeath,

You understand why right?  In 64-bit MASM you can mov qwAge, 0, since 0 is assumed to be 64-bit and the sizes are equal.  In 32-bit MASM with mov qwAge, 0, 0 is assumed to be 32-bit so it is not allowed due to a size mismatch.  So,

    xor eax, eax
    mov dword ptr qwAge,eax      ;initialize the low dword
    mov dword ptr qwAge+4,eax ;initialize the high dword

works.

You can also fistp qwAge from the FPU in 32-bit MASM. As in:

    fldz                ; corrected
    fistp qwAge


Hope that made sense.

raymond

Quotefld0
Just to make it clear, the proper mnemonic is: fldz
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

GregL

Raymond,

Sorry, it is fldz.  Corrected above.