Search code examples
assemblyaddressing-mode

LEAL instruction, what does this mean?


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

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


Solution

  • Literally translated, it is "Load the effective address EDX + EDX * 2 into EDX".

    The 80x86 has some relatively powerful addressing modes. For example, "movl (%edx, %edx, 2), %edx" would be "load the value at the effective address EDX + EDX << 1 into EDX". The LEA instruction allows the circuitry for this relatively powerful addressing to be recycled and used for other purposes.

    Part of your confusion is likely to be caused by AT&T syntax - the way addresses are written is far from natural. For comparison; for Intel syntax it would be much clearer (e.g. "lea edx, [edx+edx*2]").