tags:

views:

2718

answers:

4

For me, it just seems like a funky MOV. What's its purpose and when should I use it?

+8  A: 

lea is an abbreviation of "load effective address". It loads the address of the location reference by the source operand to the destination operand. For instance, you could use it to:

lea ebx, [ebx+eax*8]

to move ebx pointer eax items further (in a 64-bit/element array) with a single instruction. Basically, you benefit from complex addressing modes supported by x86 architecture to manipulate pointers efficiently.

Mehrdad Afshari
+13  A: 

From the "Zen of Assembly" by Abrash:

LEA, the only instruction that performs memory addressing calculations but doesn't actually address memory. LEA accepts a standard memory addressing operand, but does nothing more than store the calculated memory offset in the specified register, which may be any general purpose register.

What does that give us? Two things that ADD doesn't provide:

  1. the ability to perform addition with either two or three operands, and
  2. the ability to store the result in any register; not just one of the source operands.
Frank Krueger
+4  A: 

Maybe just another thing about LEA instruction. You can also use LEA for fast multiplaing registers by 3, 5 or 9.

LEA EAX, [EAX * 2 + EAX]   //EAX = EAX * 3
LEA EAX, [EAX * 4 + EAX]   //EAX = EAX * 5
LEA EAX, [EAX * 8 + EAX]   //EAX = EAX * 9
GJ
+12  A: 
I. J. Kennedy