LEAL instruction, what does this mean?

PhoonOne picture PhoonOne · Nov 11, 2012 · Viewed 7.6k times · Source

So first i assign edx = y by doing movl 12(%ebp) %edx.

why does leal (%edx, %edx, 2) , %edx = edx = 3*y

Answer

cHao picture cHao · Nov 11, 2012

LEA is short for "Load Effective Address". (In AT&T syntax, it is spelled "leal" for 32-bit operands.) Basically it takes the address that it calculates given the stuff in parentheses, and instead of reading or writing memory, assigns the address itself to the destination operand.

It's often used for doing address calculations, but just as often used for multiplication by certain integer constants (3, 5, and 9) by pretending a number is an address. (Addresses are just numbers, so it's not at all hard.)