The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: cobold on May 21, 2008, 09:01:05 PM

Title: A2070: invalid instruction operands - but why?
Post by: cobold on May 21, 2008, 09:01:05 PM
Hello,

seems that I still don't understand how the assembler figures out operand sizes. I thought that
f.ex.

mov al,00f34h ; ----> invalid both operands do not have same size (al = 8bit / 0f34h = 16 bit right?


on the other hand:

cmp al,0 ; immed value 0 is unspecified, but the assembler "knows" that it's a byte bec dest is register al, which is byte, correct?


So I assumed:
If you have an opcode with dest = regXXX and src = immediate value, the assembler "assumes" src to be of size XXX. It seems my assumption was wrong because:


.if [esi] == 1 ;--------> error A2070: invalid instruction operands
; but
.if dword ptr[esi] == 1 ;works


.if //CONTENT of address that esi is pointing to == 1 // now, what should 1 be, a byte, a word, a dword? How should the assembler know?
Well, because you told him before:
lea esi,Something  and Something is defined as DWORD in .data
You see esi contains the ADDRESS of "Something", and the assembler knows
- the address of the symbol (Something) plus
- knows that Something is DWORD somenum dup(whatyouwant)

So am I stupid, or is it the assembler - because it should or at least could "know" what to "assume"?



Title: Re: A2070: invalid instruction operands - but why?
Post by: jj2007 on May 21, 2008, 11:00:10 PM
Quote from: cobold on May 21, 2008, 09:01:05 PM
Well, because you told him before:
lea esi,Something  and Something is defined as DWORD in .data

You may have defined the address as Xword, but the assembler sees only [esi], and the assembler has no idea where esi will stand at runtime. So that could be a string/byte, a dword etc... that's why in this case you have to tell the stupid machine which size you mean.
Title: Re: A2070: invalid instruction operands - but why?
Post by: hutch-- on May 22, 2008, 01:08:43 AM
cobold,

Its a quirk leftover of MASM's shorthand notation. If you fully specified the line you would see the problem.


mov al,00f34h
becomes
mov al, WORD PTR 00f34h

cmp al,0
becomes
cmp al, BYTE PTR 0


It just happens to be that the assembler can identify the operand size from one side if the instruction is not ambiguous and this only occurs when a memory operand is used where you don't know its size.
Title: Re: A2070: invalid instruction operands - but why?
Post by: raymond on May 22, 2008, 02:21:42 AM
Quotemov al, WORD PTR 00f34h

And therefore, the assembler would also return the message "error A2070: invalid instruction operands", because the assembler now knows the size of both sides and realizes they are different.
Title: Re: A2070: invalid instruction operands - but why?
Post by: cobold on May 22, 2008, 04:12:17 AM
Thanks to all,

cobold