Pregunta

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

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

¿Fue útil?

Solución 2

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]").

Otros consejos

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.)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top