IL 语法分析

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 and Return Address and Local 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.

posted @   BUTTERAPPLE  阅读(503)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示