0

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%) ?
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
Muten Roshi
  • 493
  • 2
  • 5
  • 17

2 Answers2

2
  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.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
0

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.

FrankH.
  • 17,675
  • 3
  • 44
  • 63