What's the point of LEA EAX, [EAX]?

前端 未结 3 486
清酒与你
清酒与你 2020-12-04 11:12
LEA EAX, [EAX]

I encountered this instruction in a binary compiled with the Microsoft C compiler. It clearly can\'t change the value of EAX. Then w

3条回答
  •  暖寄归人
    2020-12-04 11:25

    From this article:

    This trick is used by MSVC++ compiler to emit the NOP instructions of different length (for padding before jump targets). For example, MSVC++ generates the following code if it needs 4-byte and 6-byte padding:

    8d6424 00 lea [ebx+00],ebx ; 4-byte padding 8d9b 00000000
    lea [esp+00000000],esp ; 6-byte padding

    The first line is marked as "npad 4" in assembly listings generated by the compiler, and the second is "npad 6". The registers (ebx, esp) can be chosen from the rarely used ones to avoid false dependencies in the code.

    So this is just a kind of NOP, appearing right before targets of jmp instructions in order to align them.

    Interestingly, you can identify the compiler from the characteristic nature of such instructions.

提交回复
热议问题