9
lea    0x0(%esi),%esi

I believe it has no result and is simply filling space. Is this the case?

JeremyP
  • 84,577
  • 15
  • 123
  • 161
Brian
  • 1,128
  • 7
  • 18
  • 27

1 Answers1

18

Its a NOP. It adds the contents of %esi and 0x0, and puts the result in %esi. Somebody either has a clumsy code generator or needs to fill N bytes, where this instruction is the right size.

LEA instructions execute quite fast (typically 1 clock), so this is a lot better than N nops.

The x86 being as quirky as it is, has a variety of instructions that effectively don't do anything but fill differing numbers of bytes. You may find other useless instructions of different lengths. You tend to find instructions that are long but execute in 1 clock or less.

The AMD x86-64 manual has some suggestions as to what should be used for NOPs; they suggest one of the prefix opcodes repeated a number of times before an actual NOP, IIRC. Such prefix opcodes are consumed very quickly by the instruction fetch engine; mostly their cost is hidden in instruction pre-fetch, and not in instruction execution time.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 1
    The latter, unless GCC is a clumsy code generator. Thanks for the quick response. – Brian May 08 '12 at 20:10
  • 3
    An interesting point is that `lea 0x0(%esi),%esi` is a no-op only in the 32-bit code. In the 64-bit code, this instruction additionally zeroes the higher double word of `%rsi`. So far I have seen GCC inserting such instructions only in the 32-bit code though. – Eugene May 09 '12 at 13:54
  • 1
    @Eugene: `lea 0x0(%esi),%esi` would require an additional size prefix in 64 bit mode. – Gunther Piez May 09 '12 at 18:36
  • 1
    @drhirsch: Yes, you are right, it needs "address size override" prefix (0x67) there. – Eugene May 10 '12 at 07:16