The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Broken Sword on November 09, 2005, 08:04:40 PM

Title: "error A2022" bug? (with EAX)
Post by: Broken Sword on November 09, 2005, 08:04:40 PM
Hi guys. What's wrong with mov reg, [EAX...] constructions ?
"error A2022: instruction operands must be the same size" is displayed in all cases we use "EAX" in the right part.
Title: Re: "error A2022" bug? (with EAX)
Post by: ramguru on November 09, 2005, 08:10:58 PM
You're pointing to memory and therefore must specify what you want from it byte word dword
mov eax, dword ptr [eax]
mov ax, word ptr [eax]
mov al, byte ptr [eax]
Title: Re: "error A2022" bug? (with EAX)
Post by: mnemonic on November 09, 2005, 08:12:59 PM
Hello,

how about a real life example?

Quote from: Robert on November 09, 2005, 08:04:40 PM
Hi guys. What's wrong with mov reg, [EAX...] constructions ?
"error A2022: instruction operands must be the same size" is displayed in all cases we use "EAX" in the right part.

If you code:
mov dx, eax;
The error is legitimate because you are trying to mov 32bit into a 16bit destination.
You must use a 32bit register as destination register in that case.

Also refer to the above post if you are dealing with pointers.
Take care on the size. Assembler is not happy about "implict things"  :wink
Title: Re: "error A2022" bug? (with EAX)
Post by: Broken Sword on November 09, 2005, 09:05:41 PM
:) thanks guys, but i'm not so lame in MASM...

look:

mov eax, [ebx+0Ch] ; no error
mov ecx, [edx*2+4] ; no error
mov ebx, [eax+4] ; error A2022!!!

understand? ;)

Title: Re: "error A2022" bug? (with EAX)
Post by: mnemonic on November 09, 2005, 09:50:37 PM
Quote from: Robert on November 09, 2005, 09:05:41 PM
look:

mov eax, [ebx+0Ch] ; no error
mov ecx, [edx*2+4] ; no error
mov ebx, [eax+4] ; error A2022!!!

understand? ;)

Thats why I asked for an example. Figuring something out isnĀ“t really good...

BUT:

.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib kernel32.lib
include \masm32\include\user32.inc
includelib user32.lib

.data
MsgCaption      db "Iczelion's tutorial no.2",0
MsgBoxText      db "Win32 Assembly is Great!",0

.code
start:
      push ebx
      push eax
      mov eax, offset MsgCaption
      mov ebx, [eax+4]
      pop eax
      pop ebx
invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK
invoke ExitProcess,NULL
end start


The above example assembles, links and executes just fine...

Quote from: Robert on November 09, 2005, 09:05:41 PM
:) thanks guys, but i'm not so lame in MASM...
Really?

Regards
Title: Re: "error A2022" bug? (with EAX)
Post by: Broken Sword on November 09, 2005, 10:42:19 PM
Holly Christ... It was my mistake... I've forgot 'bout

assume reg:nothing

before using

mov ..., [reg...] constructions.

nice nolame bug :)

Reggards.