Assembly instruction lea

I just want to make sure that I read this correctly:

movl 12(%ebp), %edx
leal (%edx, %edx, 4), %eax

I read the first line as: edx = [epb + 12]and the second line:eax = edx + edx*4

Can anyone clarify?

Also, what if I had the following two lines:

leal (%edx, %edx, 4), %eax
leal (%edx, %edx, 2), %eax

As soon as the second line is completed, will the register be overwritten eax?

And eax = edx + edx*4multiplies the address by 4? Or the contents of the address at 4?

+5
source share
2 answers

Wrong. In the AT & T syntax, an indication 12(%ebp)gives you a link to the address contained in %ebp, with an additional offset of 12, that is, the effective address from which the content %edx(in this case) will be loaded %ebp + 12.

. LEA Load() , , .

+7

movl 12(%ebp), %edx : edx = [ebp + 12]. ( ) ebp + 12, ( ) edx.

leal (%edx, %edx, 4), %eax : eax = edx * 5 ( eax = edx + edx * 4). leal . .

: , eax , leal (%edx, %edx, 2), %eax eax = edx * 3, eax = edx * 5.

+5

All Articles