The MASM Forum

General => The Campus => Topic started by: zedd on October 20, 2024, 02:33:34 PM

Title: 64 bit variables
Post by: zedd on October 20, 2024, 02:33:34 PM
Why does this not work: ?
mov var, 7FFFFFFFFFFFFFFDh
Quoteerror A2084:constant value too large

But this does work: ???
mov rax, 7FFFFFFFFFFFFFFDh
mov var, rax

In both cases 'var' is a qword variable. Using ml64 to assemble.

:rolleyes:  :tongue:  :undecided:  :smiley:
Title: Re: 64 bit variables
Post by: sinsi on October 20, 2024, 03:02:58 PM
Pretty sure that mov mem,imm is restricted to a 32-bit value only.
Title: Re: 64 bit variables
Post by: zedd on October 20, 2024, 03:05:26 PM
Quote from: sinsi on October 20, 2024, 03:02:58 PMPretty sure that mov mem,imm is restricted to a 32-bit value only.
Really? Even for qwords in 64 bit code?? That's rather odd.  :sad:
It seems I ought to do some more research.  ... ... grumble, grumble.

Okay, thanks.
Title: Re: 64 bit variables
Post by: sinsi on October 20, 2024, 03:19:10 PM
According to the Intel docs, the only mov is MOV r64,imm64, there's no equivalent MOV r/m64,imm64  :sad:

Quote from: sinsi on October 20, 2024, 03:02:58 PMrestricted to a 32-bit value only
Of course I meant "restricted to a maximum 32-bit value only"  :biggrin:
Title: Re: 64 bit variables
Post by: zedd on October 20, 2024, 03:29:35 PM
Yes, I was just now finding this out... and the reasons why.   :smiley:
Makes me want to stick to 32 bit.   :tongue:


Title: Re: 64 bit variables
Post by: sinsi on October 20, 2024, 03:32:51 PM
Quote from: zedd151 on October 20, 2024, 03:29:35 PMYes, I was just now finding this out... and the reasons why.   :smiley:
Makes me want to stick to 32 bit.   :tongue:
One little thing like that? You wuss :badgrin:
Title: Re: 64 bit variables
Post by: zedd on October 20, 2024, 03:37:34 PM
:biggrin:
What good are 64 bit variables if I cannot use them to their full potential?   :biggrin:

Anyway I have converted "dwtoa" from the masm32 library to "qwtoa" for use in 64 bit code. I was testing that function when I came across this issue.

So far "qwtoa" is working as expected, it converts signed qword values to ascii decimal string. Will post it when my testing is finished.
Title: Re: 64 bit variables
Post by: NoCforMe on October 20, 2024, 04:06:50 PM
Quote from: sinsi on October 20, 2024, 03:02:58 PMPretty sure that mov mem,imm is restricted to a 32-bit value only.

Is that an Intel restriction or an assembler one?

According to Felix Cloutier (https://www.felixcloutier.com/x86/mov), the largest valid MOV of an immediate value to memory uses a 32-bit value (which can be sign-extended to 64 bits).
Title: Re: 64 bit variables
Post by: zedd on October 20, 2024, 04:13:28 PM
It's a limitation of the ISA. (Intel/AMD)
We are actually running an x86 in 64 bit mode, if I correctly understood what I have read just a little while ago.

x86_64 (https://en.m.wikipedia.org/wiki/X86-64) This is not where I read about it, but explains some of the details.
Title: Re: 64 bit variables
Post by: sinsi on October 20, 2024, 04:41:54 PM
Quote from: NoCforMe on October 20, 2024, 04:06:50 PM
Quote from: sinsi on October 20, 2024, 03:02:58 PMPretty sure that mov mem,imm is restricted to a 32-bit value only.

Is that an Intel restriction or an assembler one?
It's a limitation of the CPU, there's no encoding for it.
Title: Re: 64 bit variables
Post by: sinsi on October 20, 2024, 05:11:38 PM
Quote from: zedd151 on October 20, 2024, 04:13:28 PMWe are actually running an x86 in 64 bit mode
32-bit code runs in compatibility mode under long mode if that makes sense :biggrin:
Title: Re: 64 bit variables
Post by: zedd on October 20, 2024, 05:22:14 PM
Now I am totally confused. There seems to be a lot of conflicting information around, or maybe I simply don't understand it.    :smiley:
Title: Re: 64 bit variables
Post by: daydreamer on October 20, 2024, 06:16:40 PM
Write 64 bit version of m2m macro as solution ?
It short for memory2memory
Title: Re: 64 bit variables
Post by: NoCforMe on October 20, 2024, 06:36:04 PM
Nah: just do
  MOV  [register], [64-bit value]
  MOV  [memory], [register]
Title: Re: 64 bit variables
Post by: zedd on October 21, 2024, 02:34:11 AM
The only good thing about this, is that Microsoft is off the hook for this oddity.   :biggrin:
64 bit CPU (but only sometimes).   :badgrin:
Title: Re: 64 bit variables
Post by: C3 on October 21, 2024, 03:11:44 AM
Quote from: zedd151 on October 20, 2024, 05:22:14 PMNow I am totally confused. There seems to be a lot of conflicting information around, or maybe I simply don't understand it.    :smiley:

Didn't you already got the Intel 64 and IA-32 Architectures Software Developers Manual? Check MOV's manual page. Theres all possible ways to use MOV instruction, for both 32bit and 64bit use.
Title: Re: 64 bit variables
Post by: zedd on October 21, 2024, 03:19:55 AM
@C3, nope. Reading that stuff makes my eyes bleed.   :tongue:
I prefer explanations in plain language, from others with experience with such things.   :biggrin:
Title: Re: 64 bit variables
Post by: C3 on October 21, 2024, 03:21:52 AM
Quote from: zedd151 on October 21, 2024, 03:19:55 AM@C3, nope. Reading that stuff makes my eyes bleed.   :tongue:
I prefer explanations in plain language, from others with experience with such things.   :biggrin:

Well, I do not know Intel copyright policy of that manual, so I'm not doing a screenshot of one page.
Title: Re: 64 bit variables
Post by: zedd on October 21, 2024, 03:23:47 AM
Thats okay, I have already googled for the reason and explanation.  :smiley:
.. in addition to the info already posted here.
Quote from: sinsi on October 20, 2024, 03:02:58 PMPretty sure that mov mem,imm is restricted to a 32-bit value only.
Title: Re: 64 bit variables
Post by: C3 on October 21, 2024, 03:26:53 AM
Quote from: zedd151 on October 21, 2024, 03:23:47 AMThats okay, I have already googled for the reason and explanation.   :smiley:

But another reason you to have the manual is.. that there is how instructions are build using machine language. So you can read and write the binary code/machine language. And I already know that you can do that too. But there is how the work is done by CPU Manufacturer.
Title: Re: 64 bit variables
Post by: NoCforMe on October 21, 2024, 05:56:57 AM
Quote from: zedd151 on October 21, 2024, 03:19:55 AM@C3, nope. Reading that stuff makes my eyes bleed.  :tongue:
I prefer explanations in plain language, from others with experience with such things.  :biggrin:

Check out this page (https://www.felixcloutier.com/x86/mov); it shows all the possible permuations of MOV.

Look at the end for all the variations that allow immediate values to be moved: notice that there are 4 sizes, imm8, imm16, imm32 and imm64. The only place that an immediate 64-bit value is allowed is when the destination is a register, not memory. (Keep in mind that r/mXX means "register or memory".)

It's not rocket science.