Managed Heap: GC auto manage. One process, One heap.
Call Stack: Runtime auto manage, every time when you call a method, the Record frame+1.
Record Frame save the
Method Parameter
andReturn Address
andLocal Variable
Evaluation Stack: Every Thread.
ldc.i4.1
: Put a 4 byte with value 1 to Evaluation Stack.
stloc.0
: Retrieve a value from Evaluation Stack then put it to Call Stack Record Frame V0 and set V0 = 1
stloc
Retval is an instruction that takes the result of the call to sscanf from the stack and stores it in the local
variable Retval. We need to save this value in
a local variable because we will need it later.
ldloc.0
: Put V0 to Evaluation Stack
ldloc Retval copies
the value of back onto the stack. We
need to check this value, which was taken off the stack by the instruction.Retvalstloc
box [mscorlib]System.Int32
: Retrieve a value from Evaluation Stack, then box this value type to reference type and put it to Managed Heap.
ldstr "i+j+k"
: Put the "i+j+k" reference to Evaluation Stack from Managed Heap.
ldstr “Enter a number”
is an instruction that loads the specified string constant onto the
stack. The string constant in this case is stored in the metadata. We can refer
to such strings as common language runtime string
constants or metadata string constants. You can
store and handle the string constants in another way, as explained in a few
moments, but ldstr deals exclusively with
common language runtime string constants, which are always stored in Unicode
format
call string [mscorlib] System.String::Concat(object, object)
: 從 Evaluation Stack 中取出兩個值,此二值皆為 Reference Type,下面的值當作第一個參數,上面的值當作第二個參數,呼叫 mscorlib.dll 所提供的 System.String.Concat() method 來將此二參數進行字串接合(String Concatenation),將接合出來的新字串放在 Managed Heap,將其 Reference 放進 Evaluation Stack。值得注意的是:由於 System.String.Concat() 是 static method,所以此處使用的指令是 call,而非 callvirt(呼叫虛擬)
ret
: End this call.