Is the above line loading the RAM address of the structure field or the value stored in the field to the Destination Index register ?

My understanding is that the brackets "[]" act just like the "&" in C/C++.
Posted on 2002-01-12 21:22:59 by #1_newbie
LEA (Load Effective Address) just calculates the address of the memory access and puts that in the register. To me the brackets serve little, but to remind that you are calculating the address of the access. No memory access takes place.
Posted on 2002-01-12 21:53:50 by bitRAKE
doesn't these mean the same

lea edi,

thought I read somewhere that lea was used in the 8088 days since it saved a cycle over the mov, but now-a-days it serves little advantage to use it.

I may be completely wrong though.
Straighten me out if I am, haha
Posted on 2002-01-12 23:00:11 by Rockinronstar
"To me the brackets serve little, but to remind that you are calculating the address of the access. No memory access takes place."

What exactly is the EDI doing with the stored value ?... What is the stored value... forgive me I'm really new at this...
Posted on 2002-01-12 23:31:24 by #1_newbie
Rockinronstar, no, they aren't the same: one is the address, other is the data at that address - try it in a debugger! LEA is nice because you can do fun things like: LEA edi, ...and all in one instruction! The constant multiplier must be 1,2,4,8.

Look at it this way #1_newbie.
EDI = EAX + (ECX * 8) + 45454545h

EDI is the target of the effective address calculation. EDI is just a number - could be an address, but doesn't have to be. Usually, you use the instruction to calculate a complex address and then use the address to access a structure. Or, it's used in a more tricky way - like above (that isn't going to be an address, most likely).

In assembly everything is a number - as it is within the machine. It's best not to think in terms of High-Level Langauges (HLL). In HLL you have all these types: signed, int, *void, etc... In assembly there are only numbers and the quantities in which the processor can access those numbers.
Posted on 2002-01-13 00:42:17 by bitRAKE

After LEA, the register contains the ADDRESS of the data, not the data at that address. You can then use the register as a BASE register, for whatever you want to do to the data at that address.

The OFFSET directive can often be used with MOV to accomplish the same thing, but LEA does have more addressing modes than MOV.

Posted on 2002-01-13 02:08:34 by S/390
BitRake, I'm sorry pal, but I think you missed it on that one

lea edi,

*MAY* do the exact same thing. In fact, earlier versions of MASM would replace lea with mov when appropiate.

So why both? Cause sometimes the address of a variable is not a constant. If the struct is in the .data segment, mov is fine.

LOCAL variable are quite different. They must be calculated as an offset from ebp.

There may be other examples of why lea is needed (besides cute math tricks), but I am not aware of them.
Posted on 2002-01-13 02:10:36 by Ernie
Ernie, hehe...caught by MASM again. ;)
Well, it'd be different with FASM/NASM/SpASM = my lame excuse.
Posted on 2002-01-13 02:16:47 by bitRAKE
Ummmm.... did I really post that?

Sorry, they ARE different.

1) MASM assumes the around address lables, so:

mov edi, struct.feild
mov edi,

are both the same, they load the CONTENTS of address struct.feild into edi

2) The OFFSET operator is needed to override the assumed brackets. OFFSET loads the address of the variable (of course)

mov edi, OFFSET struct.feild
mov edi, OFFSET

Are also both the same
3) lea is Load Effective Address, and will compute things like the address on the stack for LOCAL items.

mov edi, OFFSET struct.feild
mov edi, struct.feild

Now these two are equivalent for the .data segment. and that is what MASM formerly optomized for you.

Posted on 2002-01-13 10:47:42 by Ernie
You guys are cool, thank you for this info.. I will get better at this with all of your help.
Posted on 2002-01-13 13:31:17 by #1_newbie
Glad you corrected yourself Ernie. I was mentally composing a reply as I read your first post. :grin:

I can't understand why people use brackets with symbols. The only time I use them is when they're needed, as in:

mov eax,

which is quite different than:

mov eax,esi

Posted on 2002-01-13 18:08:30 by S/390
S/390, I always use brackets... and I have a reason :). Sometimes
I have "quite some" code lines. Not as much as some of those crazy
big-application/game-in-100%-win32asm, but still a decent amount :).
It really helps me in coding / finding bugs when I can spot memory
accesses even if I scroll quickly through the code. Also, since you're
really doing memory access, I think you ought to write the brackets.
I like how nasm gives you the offset if you don't write brackets,
and the data if you do... faster programming, nicer code.
Posted on 2002-01-14 05:55:10 by f0dder
Oh well f0dder, to each his own. :grin:

I guess in my case, it's a left over from mainframe assembly, that doesn't use brackets. It just seems like extra work to me, but whatever floats your boat. :o
Posted on 2002-01-14 07:28:17 by S/390
Sometimes ago I asked how I could optimize the access to a structure. It came out a nice thread: it started here

I think it may be still useful.

Posted on 2002-01-15 12:11:11 by dguzz