title: How to Learn IL on the CLR
body: <p>Since these IL codes what I see more, I like to learn how to interpret them correctly.</p>
  
  <p>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:</p>
  
  <p>Below are some sample IL codes containing what I need to know :</p>
  
  <p><strong>Sample 1:</strong></p>
  
  <pre><code>.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
  </code></pre>
  
  <p><strong>Sample 2:</strong></p>
  
  <pre><code>.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
  </code></pre>
  
  <p>I know what these codes do since I produced them :-) however I'd like to learn more about corresponding IL code.</p>
  
  <p>These samples contain IL codes like, <strong>and could you please explain command with question marks? and also what do those command stand for? So we can memorize them easily.</strong></p>
  
  <ul>
  <li>nop (for debugging - no operation)</li>
  <li>newobj (it seems it is creating new object in heap)</li>
  <li>stloc.0 ?</li>
  <li>ldloc.0 ?</li>
  <li>ret ?</li>
  <li>ldarg.0 ?</li>
  <li>ldstr ?</li>
  <li>stfld ? </li>
  <li>ldc.i4.s ?</li>
  <li>.ctor - constructor</li>
  </ul>
  
  <p>Understanding IL is important as it exposes how particular compiler produces codes and act in specific cases.</p>
  
  <p>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.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>I've found the specs and they tell these:</strong> Thanks to @usr.</p>
  
  <ul>
  <li>nop (for debugging - no operation)</li>
  <li>newobj - create a new object </li>
  <li>stloc.0 - pop value from stack to local variable</li>
  <li>ldloc.0 ? - load local variable onto the stack</li>
  <li>ret - return from method </li>
  <li>ldarg.0 - Load argument 0 onto the stack. </li>
  <li>ldstr - load a literal string</li>
  <li>stfld - store into a field of an object </li>
  <li>ldc.i4.s - Push num  onto the stack as int32 , short form. </li>
  <li>.ctor - constructor</li>
  </ul>