.NET functions disassembled

This prologue has two parts. Setting up the stackframe This stores the current EBP register on the stack and then assigns the value of the stackpointer(ESP) to EBP. push ebp mov ebp,esp If there are local variables that are stored on the stack (i.e. not enough space in the registers available) then ESP will be … Read more

IL level code debugger

The best way to do this is to use ILDASM to disassemble the managed binary, which will generate the IL instructions. Then recompile that IL source code in debug mode using ILASM, when you fire up the Visual Studio debugger you will be able to step through the raw IL. ildasm foo.exe /OUT=foo.exe.il /SOURCE ilasm … Read more

A tool for easy IL code inspection

I typically use LINQPad for that. Just paste in some C# and switch to the IL view. For example: I like it because you can also just post expressions or statements instead of a full program: Best of all, it’s free (with optional premium features).

IL Instructions not exposed by C#

I’m referring to instructions like sizeof and cpblk – there’s no class or command that executes these instructions (sizeof in C# is computed at compile time, not at runtime AFAIK). This is incorrect. sizeof(int) will be treated as the compile-time constant 4, of course, but there are plenty of situations (all in unsafe code) where … Read more

Stackoverflow doing boxing in C#

Why, if there is not significant overload of CIL’s stack for second example, does it crash “faster” than the first one? Note that the number of CIL instructions does not accurately represent the amount of work or memory that will be used. A single instruction can be very low impact, or very high impact, so … Read more

Why does my application spend 24% of its life doing a null check?

The tree is massive By far the most expensive thing a processor ever does is not executing instructions, it is accessing memory. The execution core of a modern CPU is many times faster than the memory bus. A problem related to distance, the further an electrical signal has to travel, the harder it gets to … Read more

Performance of static methods vs instance methods

In theory, a static method should perform slightly better than an instance method, all other things being equal, because of the extra hidden this parameter. In practice, this makes so little difference that it’ll be hidden in the noise of various compiler decisions. (Hence two people could “prove” one better than the other with disagreeing … Read more