A second attempt at phrasing this:
I am currently taking baby steps in getting to grips with some MSIL.
I keep hearing the 'Evaluation Stack' talked about as the stack that operations are pushed and poped as they are loaded, used etc.
So, given the following code:
public class Program
{
public static void Main()
{
var message = GetMessage();
Console.WriteLine(message);
}
public static string GetMessage()
{
return "Hello World!";
}
}
The MSIL looks as so:
.class public auto ansi beforefieldinit Program
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
}
.method public hidebysig static string GetMessage () cil managed
{
.locals init (
[0] string V_0
)
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: stloc.0
IL_0007: br.s IL_0009
IL_0009: ldloc.0
IL_000a: ret
}
.method public hidebysig static void Main () cil managed
{
.entrypoint
.locals init (
[0] string V_0
)
IL_0000: nop
IL_0001: call string Program::GetMessage()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: call void [mscorlib]System.Console::WriteLine(string)
IL_000d: nop
IL_000e: ret
}
}
I think that the lines which start with IL_xxxx
are the evaluation stack (please correct me if I am wrong). So the line call string Program::GetMessage()
is the line that calls another method.
So, I guess that question I am asking is this:
- Is each line starting with
IL_0000
a 'new' evaluation stack? - Is the call stack I see at runtime a joining\concatenation\filtering of this IL?