News:

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

A2070: invalid instruction operands - but why?

Started by cobold, May 21, 2008, 09:01:05 PM

Previous topic - Next topic

cobold

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"?




jj2007

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.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

raymond

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.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

cobold