Evaluation Stack

The evaluation stack, which is mentioned often in the preceding description of the "Hello World!" application, is the pivotal structure of MSIL applications. It is the bridge between your application and memory locations. It is similar to the conventional stack frame, but there are salient differences. The evaluation stack holds function parameters, local variables, temporary objects, and much more. In .NET, function parameters and local variables are stored in separate repositories, where memory is reserved for them. You cannot access the function parameter or local variable repositories directly. Accessing them requires moving data from memory to slots on the evaluation stack using a load command. Conversely, you update a local variable or parameter with content from the evaluation stack using a store command. Slots on the evaluation stack are either 4 or 8 bytes.

Figure 14-1 shows the relationship between the evaluation stack and the repositories for function parameters and local variables.

The evaluation stack is a stack and thereby a last in/first out (LIFO) instrument. When a function starts, the evaluation stack related to that method is empty. As the function runs, items are pushed on and popped from the evaluation stack. Before the function exits, except for a return value, the evaluation stack must be empty once again. The jmp and tail instructions, explained in the section "Branching," later in this chapter, are exceptions to this rule. If the evaluation stack is improper at exit, the run time raises an InvalidProgramException exception.

The .maxstack directive limits the number of items permitted simultaneously on the stack. The directive is optional. If the directive is not present, eight slots are reserved on the evaluation stack. The .maxstack directive is a check confirming that an application is performing as expected. Extra items on the evaluation stack are an indication of potential logic problems in an application or a security violation. In either circumstance, this is a violation worthy of a notification.

A depiction of the evaluation stack, function parameters, and local variables

Figure 14-1. A depiction of the evaluation stack, function parameters, and local variables

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.134.133