A few tests with a register dump program suggest that they all produce the same results! If this is so then I'm wondering as to the purpose of the LEA command?
Thanks.
I may look like a mule, but I'm not a complete ass.
LEA - Load Effective Address
Usage: LEA dest,src
Modifies flags: None
Transfers offset address of "src" to the destination register.
Clocks Size
Operands 808x 286 386 486 Bytes
reg,mem 2+EA 3 2 1 2-4
- the MOV instruction can often save clock cycles when used in
place of LEA on 8088 processors
8D / r LEA r16,m Store effective address for m in register r16
8D / r LEA r32,m Store effective address for m in register r32
lea edx,[edi] ;load the contents of the edi into the edx (1)
mov edx,[edi] ;load the value at edi into the edx (2)
mov edx,edi ;move the contents of the edi into the edx (3)
- (1) and (3) are equivalent.
- So what are the differences?
- (3) is faster than (1) and is preferred.
- However, mov only works with single args and cannot be used with LIST [ edi ].
- lea can take any address, e.g., lea esi , [ ebx + edi ]
Just a little something to throw into the mix. You would use LEA to handle a larger range of addresses, when a smaller range (within MOV limitations) is actually used the Assembler would substitute a MOV instruction instead (for speed).
*EDIT: LIST (in the example above) is any constant. The translation is that with MOV you can't compute an address by including it in the instructions arguments because it only takes one argument. LEA allows multiple arguments and it will compute the address from them.
Last edited by Demivec on Mon Jun 04, 2007 7:50 pm, edited 1 time in total.
lea edx,[edi] ;load the contents of the edi into the edx (1)
mov edx,[edi] ;load the value at edi into the edx (2)
mov edx,edi ;move the contents of the edi into the edx (3)
- (1) and (3) are equivalent.
- So what are the differences?
- (3) is faster than (1) and is preferred.
- However, mov only works with single args and cannot be used with LIST [ edi ].
- lea can take any address, e.g., lea esi , [ ebx + edi ]
Just a little something to throw into the mix. You would use LEA to handle a larger range of addresses, when a smaller range (within MOV limitations) is actually used the Assembler would substitute a MOV instruction instead (for speed).
lea edx,[edi+4] ;load the contents of the edi with 4 added to it into edx (1)
mov edx,[edi] ;load the value at edi into the edx (2)
mov edx,edi ;move the contents of the edi into the edx (3)
; if you try mov edx,edi+4 NO GO !!
;but (1) result edx = edi +4 (load effective address)L E A
;(3) result edx=edi cannot do :mov edx.edi+4
Lea is good because if you have a mov instruction (which will move data) you can always simply substitute the mov and leave the operands as they are and you will get the address of that data.
Since you can use mov to get the address of something as well their functionality overlaps a bit.
;enable inline asm
;put a break point everywhere
;and show the ASM debug window
v1.l=256+255;0x1ff
v2.l=256*2+255;0x2ff
v3.l=256*3+255
Debug Hex(v1)+ " " +Hex(v2) + " "+Hex(v3)
*v1=@v1
*v2=@v2;hopefully they'll be following each other
*v3=@v3
Debug "Address v1 (*v1) : " +Hex(*v1)
Debug "Address v2 (*v2) : " +Hex(*v2)
Debug "Address v3 (*v3) : " +Hex(*v3)
NOP
NOP;enough NOPs to think and watch
NOP
MOV edi,*v1 ;points to value1(value 0x1FF)(address[edi])
MOV eax,0x3ffff;a big value to show action well
LEA eax,[edi+4];eax loaded with POINTER to v2 value=2FF
MOV ebx,[eax];ebx is now loaded with 2FF
LEA ecx,[eax+4];ecx=POINTER to v3
MOV eax,[ecx-8];eax=1FF (pointer to v3 - 8)
NOP
MOV eax,[edi+4];eax=2FF
MOV ecx,[edi+2*4];points to v3
LEA ebx,[edi];will load as a pointer (LEA)
MOV eax,[ebx+8];eax = 3FF
LEA ecx,[edi+8];ecx is now a pointer to v3
MOV eax,[ecx-8];will load value1pointed to by ecx-8
NOP;
NOP;
I know what it does, but it seems I'm not able to explain it easily. When I said the functionality overlaps I mean that they can do the same, but not when given the same arguments.