.assembly Array1 {} /* // This program works as C# code: int[] x = new int[5]; x[0] = 10; x[1] = 20; Console.WriteLine("x[0] = " + x[0].ToString()); Console.WriteLine("x[1] = " + x[1].ToString()); Console.WriteLine("Array length = " + x.Length.ToString()); */ .method static public void main() il managed { .entrypoint .maxstack 8 .locals init ([0] int32[] x, [1] int32 tmp) // generated by compiler // ***************************************************** // x = new int[5]; // ***************************************************** ldc.i4.5 // load constant onto stack // create array and store reference onto stack newarr [mscorlib]System.Int32 // Store (pop) value from the stack and place it to local // variable 0. stloc.0 // ***************************************************** // x[0] = 10; // ***************************************************** ldloc.0 // Load local variable 0 onto stack (array) ldc.i4.0 // Load constant 0 to the stack (index) ldc.i4.s 10 // Load constant 10 to the stack (value) stelem.i4 // array[index] = value // The same operations with element number 1... // *************************************************** // Console.WriteLine("x[0] = " + x[0].ToString()); // *************************************************** ldstr "x[0] = " // load string onto stack // STACK: "x[0] = " (stack is shown from local // variables) ldloc.0 // load variable 0 onto stack ldc.i4.0 // load constant 0 onto stack // STACK: "x[0] = " -> x -> 0 // Load address of array element onto stack. ldelema [mscorlib]System.Int32 // STACK: "x[0] = " -> pointer to Int32 instance // 10 // Call non-static function System.Int32::ToString(). call instance string [mscorlib]System.Int32::ToString() // STACK: "x[0] = " -> "10" // call static System.String::Concat(string, string) call string [mscorlib]System.String::Concat (string, string) // STACK: "x[0] = 10" // call static System.Console::WriteLine(string) call void [mscorlib]System.Console::WriteLine(string) // STACK: empty // The same operations with element number 1 ... // ***************************************************** // Console.WriteLine("Array length = " + x.Length.ToString()); // ***************************************************** ldstr "Array length = " // load string onto stack // STACK: "Array length = " ldloc.0 // load variable 0 to stack // STACK: "Array length = " -> x ldlen // push the length of array onto stack // STACK: "Array length = " -> 5 conv.i4 // Convert to int32, pushing int32 onto stack // STACK: "Array length = " -> 5 stloc.1 // store to local variable 1 (tmp) // STACK: "Array length = " ldloca.s tmp // load address of variable tmp onto stack // STACK: "Array length = " -> &tmp call instance string [mscorlib]System.Int32::ToString() // STACK: "Array length = " -> "5" call string [mscorlib]System.String::Concat (string, string) // STACK: "Array length = 5" call void [mscorlib]System.Console::WriteLine(string) // STACK: empty ret }