> From reading the IL code generated by MS csc.exe, it seems that NOP is > used in the same way as your label instruction.
Indeed it does appear so. Even when branching backwards (back to the start of a loop) csc inserts a NOP. The NOPs serve another purpose, too; they tend to mark the end of blocks of code, which can aid debugging. When single-stepping through code, the debugger often stops at and highlights the close brackets. That's also a useful place to put a breakpoint at times. In many cases, neither of these would be possible if the NOP weren't there. For this reason (regarding Augusto's suggestion), you mustn't remove the NOPs when emitting debugging information. However, marking branch points and providing debug step points are two different things which happen to be handled the same way by csc. I find some of the additional debug step points this creates very annoying, e.g. 3 steps at the head of a foreach loop. My compiler uses a label pseudo-op for branching and emits NOPs at the ends of certain blocks for debugging purposes (only when debugging is active). This gives me more control over where single-stepping occurs in the debugger. --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~---
