This is a mirror of official site: http://jasper-net.blogspot.com/

Subterranean IL: Introduction

| Sunday, November 7, 2010
Today, I'll be starting a new series of blog posts on 'Subterranean IL' - a look at the low-level IL commands available to .NET compilers, what each command does (or at least the more interesting commands) and why each command does what it does. One of the first things I'll be looking at are the IL commands used in a generic method or a method in a generic class. However, to start off, we need to understand the basic data structures and datatypes used by the VES (Virtual Execution System) when executing a method.

The Execution Stack

The execution stack is where all the action happens in a .NET method. IL instructions all either operate on values currently on the execution stack, or copy values to and from the execution stack. However, the stack isn't generally used for storage of values throughout a method's execution; that's what local variables are for. As an example, here's a commented outline of the IL corresponding to the following C# method:

public static int AddFive(int value) {
   int newValue = value + 5;
   return newValue;
}
.method public static int32 AddFive(int32 'value') {
   .maxstack 2
   
   // declare 1 local variable
   .locals init ([0] int32 newValue)

Read more: Simple-talk

Posted via email from .NET Info

0 comments: