ASP.NET
  Home arrow ASP.NET arrow Page 4 - Finishing an Introductory Look at 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

Finishing an Introductory Look at CIL
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-11-26

    Table of Contents:
  • Finishing an Introductory Look at CIL
  • Local Variables
  • Loops
  • Loops Continued
  • The Outer Loop
  • The Inner Loop
  • Conclusion

  • 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


    Finishing an Introductory Look at CIL - Loops Continued


    (Page 4 of 7 )

    Now it's time to move on to the second step. If the flow of the program isn't interrupted by branching in the previous step, then the flow of the program will continue to this step, which is, in the program, located immediately after.

    The third step in our list is the performance of whatever is in the body of the loop. So, we simply need to print out the value of the counter. This part isn't hard, and we did something like it in the last part:


    // loop contents

    ldstr "Number: {0}"

    ldloc i

    box int32

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


    Now comes the counter. We have to add one to the value of the counter. This involves putting both numbers on the stack:


    ldc.i4.1

    ldloc i


    Adding the two values together is extremely simple:


    add


    To finish up, we simply store the value back in the counter variable:


    stloc i


    All that remains in our loop is to go back to the condition section of our method. This is done through an unconditional branch:



    br.s loop_condition


    Finally, we need to provide a label after the loop, which our condition section jumps to if the condition is false:


    loop_done:


    ldstr "Done!"

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


    Here's the completed program:


    .assembly extern mscorlib {}

    .assembly LoopTest {}


    .class public LoopTest

    {

    .method public static void Main(string[] args)

    {

    .entrypoint

    .maxstack 2

    .locals init (int32 i)


    // assign 1 to i

    ldc.i4.1

    stloc i


    loop_condition:


    ldloc i

    ldc.i4 10

    bgt loop_done


    // loop contents

    ldstr "Number: {0}"

    ldloc i

    box int32

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


    // loop counter

    ldc.i4.1

    ldloc i

    add

    stloc i


    // check the value of i again

    br.s loop_condition


    loop_done:


    ldstr "Done!"

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


    ret

    }

    }


    More ASP.NET Articles
    More By Peyton McCullough


       · Hello,This is a continuation of the last article. It finishes the main example...
     

    ASP.NET ARTICLES

    - 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
    - Building a Simple Storefront with LINQ





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