News:

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

Odd error

Started by ecube, January 24, 2007, 09:48:56 AM

Previous topic - Next topic

ecube

i'm working on a pretty big project in masm, has over 50 source files thus far and recently I keep getting this odd error

error A2022: instruction operands must be the same size

when I do something like

testproc proc
local val1:dword
local val2:dword

mov eax,val1
add eax,val2
mov eax,[eax]  <-----error A2022: instruction operands must be the same size

ret
testproc endp


anytime I do a mov reg,[reg] I get that error really, any help would be much appreciated, thanks.

mnemonic

Hi E^cube,

as far as I remember it should be written as
mov eax, dword ptr [eax]
Same goes for word and byte sized reg, mem moves.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

Shantanu Gadgil

Quoteas far as I remember it should be written as
mov eax, dword ptr [eax]

Nope...not really...
mov eax, [eax]
means mov eax, dword ptr [eax] if register size is 32 bit

MASM should not fire an error for the command
mov eax, [eax]
Not only have I used instructions like mov eax, [ebx] etc, I have used that particular instruction (mov eax, [eax] ) many times too.
Could it have something to with not having the .386 directive or something like that?

Also the "automatic meaning" goes for other regsizes too...
mov al, [esi]
implies
mov al, byte ptr [esi]
...
mov ax, [esi]
implies
mov ax, word ptr [esi]

Note: This "automatic understanding" is only when both the items are regs!!!

Regards,
Shantanu
To ret is human, to jmp divine!

Ratch

E^cube,

Quoteanytime I do a mov reg,[reg] I get that error really, any help would be much appreciated, thanks.

     You should put a semicolon in the line to designate your comments.  Then it will assemble OK.  See ZIP file below.  Ratch

mov eax,[eax]  ; <-----error A2022: instruction operands must be the same size

[attachment deleted by admin]

Shantanu Gadgil

QuoteYou should put a semicolon in the line to designate your comments...
Eh?  :eek

Are you saying that he should put a comment in front of that instruction in his original code?
If so, I am running an app here with any comment or anything in the line.

I am pretty sure E^cube was just pointing out the line with the fancy arrow thing next to it, and that wouldn't be his _actual_ code!!!

Anyway,
E^cube,
I am sure there is some other issue than the instruction itself, because it works fine here...just checked it again.

Could you please tell us what flags you are using while assembling? What version of ML/MASM32 etc...

BTW, all the following work fine:
mov eax, offset szTemp
mov eax, [eax]

mov eax, offset szTemp
mov al, [eax]

mov eax, offset szTemp
mov ax, [eax]


szTemp can be declared in the data or data? section, didn't make any difference!!!

Regards,
Shantanu
To ret is human, to jmp divine!

raymond

E^cube
Quotei'm working on a pretty big project in masm

Could you confirm that you are actually using MASM as against some other assembler such as NASM, TASM, FASM, etc...

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

MichaelW

I have seen similar problems when mixing 32-bit and 16-bit code.
eschew obfuscation

hyperon

To E^cube:
Perhaps you used the operator PTR in another subroutine, which forces eax to be treated as having the other type, for example:

Assume eax:PTR YourDataClass

And you have not cancelled it.