Hi everybody,

It's been a while, but I'm back learning assembler again.
I've just spent a few days pouring over all the information about the various addressing modes - I think I've more or less got it all sorted, but there is one aspect which is REALLY confusing me.

In Hutch's "Introduction to 32 bit Assembler", "Data Types in Registers" he says:

mov edx, lpMemvar ; copy variable address into EDX

...but then a few lines later we have:

mov eax, lpMem ; copy memory value into register

Now, as I understand it, to the assembler (MASM) a label such as a code label or the identifier for a variable IS an address, but wherever I look I find conflicting information about whether an instruction such as MOV (as in the above examples) copies the address of the variable, or the value of the variable which is stored at that address.

A fairly simple question, but a pretty fundamental one I would say.

Could anyone please help with a definitive answer on this. Maybe also then, on the use of the "offset" operator - when, why etc.
Posted on 2002-10-26 12:35:24 by Hamper
I've done some more swotting-up on the subject.

I guess that Hutch's (and a few others') notes are based upon you somehow knowing that the variable names used are to be "taken as read" as having already been initialized with certain values, e.g. the effective address of a variable in memory. If that's so, then OK, but it could be clearer. Learning assembler is tricky enough as it is.

I still can't see any point to the directive OFFSET though. The instruction LEA seems to do everything that OFFSET can do, and without adding another layer of complication onto the assembler. Is OFFSET just another "bells and whistles" construct that doesn't actually do anything that you can't do anyway? Does it encode based on the use of the LEA instruction upon assembly? Are the following statements the same, in effect?

myString byte "Hello",0

mov ebx, offset myString
lea ebx, myString
Posted on 2002-10-26 16:02:41 by Hamper
lea ebx,myString

and

mov ebx,OFFSET myString

Give the same results but in principle, they are different. If i am not wrong, OFFSET is a precompiler method, while using lea it takes up cpu time. When you using ADDR myString ,MASM expands it to lea eax,myString and later push eax.
Posted on 2002-10-26 20:19:29 by roticv