Question

I found this code:

lea 0x10(%edi),%esi
mov %esi,0x4(%edi)

but I really don't understand this combination.

  1. what is exactly happens on the stack on the lea-command.
  2. is it not easier just to write: mov 0x10(%edi),0x4(edi%) ?
Was it helpful?

Solution

  1. Nothing happens to the stack.
  2. It might be, but that's not a valid instruction. mov supports at most one memory operand. Anyway, your example appears to have different semantics (as mentioned by @zch below).

You can grab a copy of the Intel Software Developers Manuals and read all you want about it.

Edit: Regarding your questions "what value is written in %esi ? lea is calculation the offset? of which address?"

esi gets edi + 0x10; that's what that 0x10(%edi) means. lea stands for "load effective address". That is, it interprets edi as a pointer, and increments it by 0x10, storing the result in esi.

OTHER TIPS

The use of lea vs. mov in x86 assembly is the same kind of thing as, in C/C++, saying:

char *ptr;
...
ptr = &val;

vs.

char *ptr;
...
*ptr = val;

lea calculates the address, mov (or other instructions with memory operands) dereferences (accesses) it.

So lea does in x86 assembly what's called "pointer arithmetics" in C/C++ - no memory access is involved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top