Is it impossible to use "offset" or "ADDR" commands within a function ?
i try a simple
"mov eax,offset temp" and i get "invalid operand for OFFSET"
"mov eax,ADDR temp" and i get "syntax error : ADDR".
these are used in a PROC i wrote. i also declared "LOCAL temp:DWORD".
ADDR can only be used with invoke (but of course you can use offset with invoke too). In all other cases, use offset.
But this does not apply to local variables, as they don't have a fixed offset. If you have this code:
.data
var dd 500
.code
mov eax, offset var
this will assemble as something like:
mov eax, 403000h
Where the 403000h is the offset of the variable. This offset is fixed, it never changes. But as local variables are stored on stack, their location is not always the same (they even don't exist outside the procedure :-)). They are accessed by using a relative offset to ebp, like this:
somefunction proc
LOCAL localvar:DWORD
mov eax, localvar
the mov eax, localvar will assemble as:
mov eax, dword ptr
Now you can see why you can't put the offset of the local variable in eax, the offset = ebp-4.
To get the offset, you need to put ebp-4 in eax. This is what lea (load effective address) does:
lea eax, localvar
this assembles to:
lea eax,
this is the same as : eax = ebp - 4 (note that the brackets in lea don't have the same meaning as in mov etc.).
Thomas