I Just want to make sure I am reading this right:
movl 12(%ebp), %edx
leal (%edx, %edx, 4), %eax
I read the first line as: edx = [epb
The instruction movl 12(%ebp), %edx
means: edx = [ebp + 12]
. This is a memory reference (a read operation) to the address ebp + 12
whose contents (a double word) are read to edx
register.
The instruction leal (%edx, %edx, 4), %eax
means: eax = edx * 5
(which is a simplification of eax = edx + edx * 4
). The leal
instruction doesn't do memory references. It only performs arithmetic with registers.
As an answer to your second question: Yes, eax
would be overwritten because the instruction leal (%edx, %edx, 2), %eax
means eax = edx * 3
which is different from the first instruction, eax = edx * 5
.
You're right. The LEA
instruction is used to Load (the) Effective Address, and can be used for address arithmetic and sometimes also ordinary arithmetic, if you don't need the flags.