The. NET CIL series second: Stack-and-stack--cil based on the nature of the stack

Source: Internet
Author: User

In the previous. NET CIL first: CIL Introduction and introduction We briefly introduced the nature of CIL programming and learned the value of CIL programming. The instructions, attributes, and opcode of CIL are also described. The following text will appear frequently: instructions, attributes, opcode, and the keywords. So make sure you know what they mean.

Into stacks and stacks: CIL based on the nature of stacks

Advanced like C #. NET language, always trying to hide the underlying implementation as much as possible. A less noticeable aspect of net development is that CIL is actually a fully stack based development language. Recall the functionality of the stack type in the familiar System.Collections namespace, which is used to press a value into the stack, and also to eject the value of the top of the stack for use. Of course, CIL developers do not use System.Collection.Stack to implement stacks and stacks, but they are connected in a way of thinking.

Officially, the part of the CIL used to handle this stack implementation is called the virtual execution stack. From the following introduction, you will see that CIL provides a series of opcode to complete the indentation value into this stack, the term of which is called load. Also, CIL defines a series of opcode to move the value of the top of the stack into memory (for example, local variables), a process called storage (store).

CIL does not allow direct access to a data, including local variables, variables passed in a method, or field data of a type. In order to achieve access, data must be displayed to the stack and ejected when it is used. Keep this in mind, because this can explain why the CIL code looks a bit redundant.

The following is a simple function printmessage () with no parameters and return values to understand how CIL applies the stack model. When implementing this method, we will only output a local string variable to the standard output stream.

public void PrintMessage()

{

    string myMessage = "Hello";

    Console.WriteLine(myMessage);

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.