For testing purposes I have written some x86 assembly code:
lea ebx, [esi]
I changed the line and wrote:
mov ebx, esi
and the program does exactly the same. Why?
In esi , there is stored the address of a string. In the first line, I stored the address of the address of the string, right? And in 2 line, it should store only the address of the string.
Here, Amit Singh Tomar wrote that
mov eax ,var == lea eax [var]
and when I read and applied that to my case, then I was a little bit confused.
edit: I also try to translate that two lines above into pseudo-C code and it looks like this (I assume that ebx and esi are pointers):
(1st line with lea):
unknownType *ebx = &(*esi) // since the brackets mean dereferencing,
// I use the dereferencing operator *
// and since lea is equal to the
// address of operator, I came to this result
(2nd line with mov):
unknownType *ebx;
ebx = esi ; // in the second case, ebx would point also
// to the address of the string
But this would not be the same, right?
Your translation into pseudo-C is correct (assuming
unknownType *esi;
above the code shown). What you haven't realized is, again in pseudo-C, thatfor all valid pointers
x
. You have not taken the address of the address of the string; you have only taken the address of the string.In the original 8088/8086, I don't think there was any difference and I wondered the same question. Maybe one was a byte shorter or executed in a cycle less.
However, since the 80386, the effective addressing modes are expanded.
With that,
lea
is significantly more useful since there is no single-instruction way to doHowever, this is perfectly valid and useful: