I don't see difference between mov eax, ebp and lea eax, [ebp]

Started by jackheroes, August 16, 2011, 10:12:20 AM

Previous topic - Next topic

jackheroes

I don't see difference between "mov eax, ebp" and " lea eax, [ebp] "
I think lea instruction is troublesome here, it dereferences ebp and gets its' address again, like c++( p1 = &(*p) ).
Why don't just use mov eax, ebp. I have tested both statements, they resulted the same thing.

qWord

Quote from: jackheroes on August 16, 2011, 10:12:20 AM
I don't see difference between "mov eax, ebp" and " lea eax, [ebp] "
same operation encoded in two different instructions.
In your case LEA does exact the same as MOV. However, LEA has the capacity to do some additional arithmetic (SIB).
lea eax,[ebp+4*ecx-4]
FPU in a trice: SmplMath
It's that simple!

dedndave

you just need to choose the right instruction for the job
in your case, i suspect MOV is the right one

LEA is used if the CPU needs to calculate the address
for example, if you wanted the address of [EBP+4], rather than [EBP]
        lea     eax,[ebp+4]
that is like moving EBP into EAX, then adding 4 to it

raleeper

The 2 instructions assemble as:
mov, eax, ebp           8bc5
lea, eax, [ebp]           8d4500

but

lea, eax, [ebp+4]       8d4504





dedndave

yes - all the [EBP] intructions are coded with a byte offset

8D4500 is actually
        lea     [ebp+00]