What's the difference between:

mov eax,

and

mov eax,memvar
Posted on 2003-10-12 22:21:05 by optimus
In MASM there is no difference. Both syntaxes are supported but they are the same. The reason is that memvar is actually a static address label. When you mov it into the register it is automatically dereferenced whether or not you choose to use square brackets. Since the value of memvar is static and cannot be changed it is redundant to insist that it is dereferenced after all you cannot mov a new address into the label and if you wish the actual address of the label you use OFFSET or ADDR. Most assemblers will throw an error if you attempt to use mov eax,memvar but masm assumes the presence of the brackets.
Posted on 2003-10-12 22:32:35 by donkey
if a pointer is stored in memvar, and i want to refer to the value pointed by this pointer, "mov eax, " does not do that, right? how to do that with one instruction or it's just impossible?
Posted on 2003-10-13 00:01:18 by optimus
optimus,

MASM uses named variables to replace code so if you have a LOCAL value created on the stack,


LOCAL var:DWORD
....
mov eax, var

What you have actually coded is something like,


mov eax, [ebp-24]

which is the stack address of the allocated variable space. When you enclose a named variable with square brackets you are trying to code something like,


mov eax, [[ebp-24]]

Fortunately MASM ignores the mistake.

You use square brackets to dereference an address as follows,


mov eax, address
mov eax, [eax]

MASM is older than any other commonly available assembler today and it has been the standard for a very long time. Some of the others that use square brackets routinely have to do so because they are not as powerful in the parsing as MASM.

Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2003-10-13 00:14:18 by hutch--

if a pointer is stored in memvar, and i want to refer to the value pointed by this pointer, "mov eax, " does not do that, right? how to do that with one instruction or it's just impossible?

First off a pointer is not stored in memvar, it is a pointer. It is used to represent a specific address in memory, it does not actually contain anything it is simply a named label (ie symbol) used by the assembler.

The CPU is not capable of dereferencing using a memory address, it can only dereference with a register so the limitation is not in MASM but in the x86 family of CPUs. You must first move the address into a register then dereference it from there.
Posted on 2003-10-13 00:59:06 by donkey