Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

x86 - lea assembly instruction

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 + 12], and the second line as: eax = edx + edx*4

Can anybody clarify?

Also, what if I had the following two lines:

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

Once the second line is executed, would the eax register be overwritten?

And the eax = edx + edx*4 is multiplying the address by 4? Or the contents of the address by 4?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...