Search code examples
assemblyx86addressing-mode

assembly code:understanding the lea command


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%) ?

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.