why I cant use the offset operand only with global varables?

And why does this instuction not work ?

a dword 200 dup(0)
b dword 3
PUSH OFFSET a[b] ;<<--does not work
PSUH OFFSET a[3] ;<<--work

Thanks in advance
Posted on 2003-08-20 14:50:13 by Bubu-Boy
push offset a is not the same as push offset a[0] but becomes something like push offset a+b or something like that. Remember that brackets means addition.
Posted on 2003-08-21 02:57:18 by roticv
I think that problem here is that you can't have two memory operands in one instuction.
This is true for most (if not all) instructions like
mov var1,var2
add var1, var2
Posted on 2003-08-21 20:36:55 by Mikky
The answer is the same for both questions.
OFFSET is an assembler directive, it is not an instruction. The assembler must resolve it at assemble time, and the location of LOCAL variables is non-deterministic (they are related to ebp, who's value can change). As such, you must use the lea instruction which is specifically designed to take a register and a relative offset (lea eax, MyLocal == lea eax, ).

Similarly with the mov eax, a, the value of b is not constant (or at least potentially it is not constant). So the assembler cannot resolve the value of b at run-time, and so cannot resolve the OFFSET directive.

Posted on 2003-08-22 03:05:10 by Mirno