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
50 years too late but hey.
Nop's are useful if you are typing assembly code by hand. If you had to remove code, you could nop the old opcodes.
similary, you could insert new code by overwriting some opcode and jump somewhere else. There you put the overwritten opcodes, and insert your new code. When ready you jump back.
Sometimes you had to use the tools which were available. In some cases this was just a very basic machinecode editor.
Nowadays with compilers the techniques make no sense whatsoever anymore.
They could be using them to support edit-and-continue while debugging. It provides the debugger with room to work to replace the old code with new without changing offsets, etc.
A somewhat unorthodox use are NOP-Slides, used in buffer overflow exploits.
One classic use for them is so that your debugger can always associate a source-code line with an IL instruction.
Do the .NET compilers align the MSIL output? I'd imagine it might be useful for speeding up access to the IL... Also, my understanding is that it's designed to be portable and aligned accesses are required on some other hardware platforms.
In the software cracking scene, a classic method to unlock an application would be to patch with a NOP the line that checks for the key or registration or time period or whatnot so it would do nothing and simply continue starting the application as if it is registered.