What's the purpose of the CIL nop opcode?

前端 未结 19 1277
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 10:42

I\'m going through MSIL and noticing there are a lot of nop instructions in the MSIL.

The MSDN article says they take no action and are used to fill space if the opc

相关标签:
19条回答
  • 2020-12-07 10:45

    NOPs serve several purposes:

    • They allow the debugger to place a breakpoint on a line even if it is combined with others in the generated code.
    • It allows the loader to patch a jump with a different-sized target offset.
    • It allows a block of code to be aligned at a particular boundary, which can be good for caching.
    • It allows for incremental linking to overwrite chunks of code with a call to a new section without having to worry about the overall function changing size.
    0 讨论(0)
  • 2020-12-07 10:45

    In one processor I worked for recently (for four years) NOP was used to make sure the previous operation finished before the next operation was started. For instance:

    load value to register (takes 8 cycles) nop 8 add 1 to register

    This made sure register had the correct value before the add operation.

    Another use was to fill in execution units, such as the interrupt vectors which had to be a certain size (32 bytes) because address for vector0 was, say 0, for vector 1 0x20 and so on, so the compiler put NOPs in there if needed.

    0 讨论(0)
  • 2020-12-07 10:47

    I've also seen NOPs in code that modifies itself to obfuscate what it does as a placeholder (veeery old copy protection).

    0 讨论(0)
  • 2020-12-07 10:47

    I used NOPs to automagically adjust the latency accumulated after entering an ISR. Very handy to nail timing dead on.

    0 讨论(0)
  • 2020-12-07 10:48

    The first assembly I learned was SPARC so I'm familiar with the branch delay slot, if you can't fill it with another instruction, usually the instruction you were going to put above the branch instruction or increment a counter in loops, you use a NOP.

    I'm not familiar with cracking, but I think is common to overwrite the stack using NOP so you have not to exactly calculate where your malicious function begins.

    0 讨论(0)
  • 2020-12-07 10:48

    nop will be usefull in memory corruption exploit payload. Of course nop is similiar with xchg eax, eax

    0 讨论(0)
提交回复
热议问题