x86 lea instruction

2019-05-24 13:49发布

问题:

I am trying to get a good grip on the LEA instruction in x86:

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

Given these two lines, i know that:

eax = edx + edx*4

and then

eax = edx + edx*2

Two questions. First, if these instructions appear in sequence as in this example, the eax register is overwritten once the second line executes? And what exactly would be loaded into the register? Another address? Or is this doing arithmetic on the values that these registers point to?

回答1:

if these instructions appear in sequence as in this example, the eax register is overwritten once the second line executes?

Yes (it is overwritten after both instructions)

And what exactly would be loaded into the register? Another address?

The memory address described by EDX + the offset stored as value in EDX multiplied by 2