I'm trying to disassemble my C# code and then debug it on assembly language level. Let's say we have a simple C# method:
var a = 1235;
var b = ++a;
var c = ++b;
Console.WriteLine("test");
Console.ReadKey();
I've found two different ways how to get an assembly code. The first one is to start C# code debugging in VS and then open Disassembly window. Here we have the following code.
Everything is OK and assembly code is pretty much simple and short but the problem is that the logic of this assembly code differs from the logic of the IL code generated by ildasm.
So here is the second way. We can compile C# code, use ildasm to get the IL code from PE file and then use ilasm to generate PE file back. Now we have the following assembly code.
As you can see this assembly code is more like the IL code but it contains much more instructions and it is more complicated.
AFAIK C# compiles to CIL code and then to an assembly code in both cases. But it seems to be that in the first way it just compiles to an assembly code.
So the question is why the assembly code of the first method differs from the IL code? And why the assembly code of the first method differs from the assembly code of the second method?