ASP.NET
  Home arrow ASP.NET arrow Page 3 - An Introduction to CIL
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

An Introduction to CIL
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-11-19

    Table of Contents:
  • An Introduction to CIL
  • Classes
  • A Short Interruption
  • Back to Hello World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    An Introduction to CIL - A Short Interruption


    (Page 3 of 4 )

    Before we continue with our main conversion task, let's break off for a second, temporarily turning our program into a “hello world” example, just to explore some basic concepts without taking a dive (otherwise, with our example, it is quite a dive).

    With C#, operations and method calls are all quite readable – the syntax all makes sense and is what we're used to. CIL, however, is quite different. Up until now, CIL wasn't too different from C#. Now, however, some clear differences will appear. To perform operations, programs use what is called a stack. Basically, first, values are pushed onto the stack. Then, some sort of operation is performed which involves popping those values off of the stack and, if applicable, pushing a result back onto the stack. For example, consider addition. Let's add the numbers three and four together. First, we push three onto the stack:


    3


    Then, we push four onto the stack:


    4

    3


    Notice how it is stacked on top of the previous value. Now, in order to perform the addition, we need to take both values off of the stack, add them up, and then push the value onto the stack. After that's done, the stack looks like this:


    7


    Now we have the result. Let's turn to a more complicated example: a method call. Consider the following method call in C#:


    Console.WriteLine("Two numbers: {0} and {1}", 73, 82);


    C# makes this easy, but how does this look in CIL when we compile it? The resulting code seems quite scary:


    ldstr "Two numbers: {0} and {1}"

    ldc.i4.s 73

    box [mscorlib]System.Int32

    ldc.i4.s 82

    box [mscorlib]System.Int32

    call void [mscorlib]System.Console::WriteLine(string, object, object)


    It only seems scary, though. Let's take it line-by-line and examine what it does to the stack. The first line starts with ldstr, which stands for “load string.” As its name suggests, it loads a string onto the stack. So, after it's executed, the stack looks like this:


    Two numbers: {0} and {1}”


    The next line isn't any scarier. It loads the number 73 onto the stack. The stack now looks like this:


    73

    Two numbers: {0} and {1}”


    After that, we box the number at the top of the stack (73), turning it into an Int32:


    73 (Int32 object)

    Two numbers: {0} and {1}”


    The next two lines are very similar, and after they are executed, the stack looks like this:


    82 (Int32 object)

    73 (Int32 object)

    Two numbers: {0} and {1}”


    Now, the final line is where the action takes place. We call the WriteLine method of System.Console. Note that we have to specify the parameters of the method we want – this is important! Here, we specify that we want the WriteLine method that takes a string and then two objects. When this line is executed, an object is first popped off of the stack, followed by another object and then finally a string. Notice how this is done in reverse order – this, too, is important!

    More ASP.NET Articles
    More By Peyton McCullough


       · Hello,This article is the first part of a two-part introduction to the basics of...
     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT