The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: jackheroes on August 16, 2011, 10:12:20 AM

Title: I don't see difference between mov eax, ebp and lea eax, [ebp]
Post by: jackheroes on August 16, 2011, 10:12:20 AM
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.
Title: Re: I don't see difference between mov eax, ebp and lea eax, [ebp]
Post by: qWord on August 16, 2011, 10:56:27 AM
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]
Title: Re: I don't see difference between mov eax, ebp and lea eax, [ebp]
Post by: dedndave on August 16, 2011, 02:07:32 PM
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
Title: Re: I don't see difference between mov eax, ebp and lea eax, [ebp]
Post by: raleeper on August 17, 2011, 01:23:29 AM
The 2 instructions assemble as:
mov, eax, ebp           8bc5
lea, eax, [ebp]           8d4500

but

lea, eax, [ebp+4]       8d4504




Title: Re: I don't see difference between mov eax, ebp and lea eax, [ebp]
Post by: dedndave on August 17, 2011, 01:55:07 AM
yes - all the [EBP] intructions are coded with a byte offset

8D4500 is actually
        lea     [ebp+00]