The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ecube on January 24, 2007, 09:48:56 AM

Title: Odd error
Post by: ecube on January 24, 2007, 09:48:56 AM
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.
Title: Re: Odd error
Post by: mnemonic on January 24, 2007, 09:59:00 AM
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.
Title: Re: Odd error
Post by: Shantanu Gadgil on January 24, 2007, 12:19:52 PM
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
Title: Re: Odd error
Post by: Ratch on January 24, 2007, 03:16:03 PM
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]
Title: Re: Odd error
Post by: Shantanu Gadgil on January 24, 2007, 04:25:42 PM
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
Title: Re: Odd error
Post by: raymond on January 24, 2007, 04:50:18 PM
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
Title: Re: Odd error
Post by: MichaelW on January 24, 2007, 06:28:59 PM
I have seen similar problems when mixing 32-bit and 16-bit code.
Title: Re: Odd error
Post by: hyperon on January 25, 2007, 03:10:18 PM
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.