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);
}