Since these IL codes what I see more, I like to learn how to interpret them correctly.
I couldn't find a documentation like C# Compiler or any other so I think I can pretty much take care of the rest after I learn this common ones:
Below are some sample IL codes containing what I need to know :
Sample 1:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 15 (0xf)
.maxstack 1
.locals init ([0] class EnumReflection.DerivedClass derivedClass)
IL_0000: nop
IL_0001: newobj instance void EnumReflection.DerivedClass::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: callvirt instance void EnumReflection.DerivedClass::WriteOutput()
IL_000d: nop
IL_000e: ret
} // end of method Program::Main
Sample 2:
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 38 (0x26)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldstr "Hello"
IL_0006: stfld string EnumReflection.DerivedClass::hello
IL_000b: ldarg.0
IL_000c: ldstr "World"
IL_0011: stfld string EnumReflection.DerivedClass::world
IL_0016: ldarg.0
IL_0017: ldc.i4.s 123
IL_0019: stfld int32 EnumReflection.DerivedClass::age
IL_001e: ldarg.0
IL_001f: call instance void EnumReflection.BaseClass::.ctor()
IL_0024: nop
IL_0025: ret
} // end of method DerivedClass::.ctor
I know what these codes do since I produced them :-) however I'd like to learn more about corresponding IL code.
These samples contain IL codes like, and could you please explain command with question marks? and also what do those command stand for? So we can memorize them easily.
Understanding IL is important as it exposes how particular compiler produces codes and act in specific cases.
However, I couldn't find a nice docs which contain examples as well about IL. CLR with C# 3.0 is a good book however eventually it isn't a IL book so it doesn't explain everything about IL.
EDIT:
I've found the specs and they tell these: Thanks to @usr.
This article introduces the Cross-Language capabilities of CLR environment (Common Language Runtime Environment) and its constituent language IL (Intermediate Language).
In this post we will discuss about CLR (Common Language Runtime), CLS (Common Language Specification) , CTS (Common Type System), JIT (Just in Time Compiler), IL (microsoft intermediate language), Managed Code and Unmanaged Code.
Intermediate language (IL) is an object-oriented programming language designed to be used by compilers for the . NET Framework before static or dynamic compilation to machine code. The IL is used by the . NET Framework to generate machine-independent code as the output of compilation of the source code written in any .
There are a few books that do cover IL:
Also some books on reverse engineering have sections on IL.
See also:
Microsoft standardized the CLR and published those standards. Partition III contains a wealth of information about IL/CIL and is suitable for learning. It is an excellent document.
You can also learn IL by example. Compile a few simple methods in C# and look at the IL in reflector (it has an IL-mode).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With