了解IL汇编循环

IL代码,

cpp 复制代码
.assembly extern mscorlib {}
 
 .assembly Test
 {
     .ver 1:0:1:0
 }
 .module test.exe
  
 .method static void main() cil managed
 {
     .maxstack 8
     .entrypoint
     .locals init (int32, int32)
   
     ldc.i4 4
     stloc.0        //Upper    limit of the Loop, total 5 
     ldc.i4 0 
     stloc.1        //Initialize the Starting of loop 

Start:     
     //Check if the Counter exceeds
     ldloc.1 
     ldloc.0 
     bgt Exit //If Second variable exceeds the first variable, then exit

     ldloc.1
     call void [mscorlib]System.Console::WriteLine(int32)

     //Increase the Counter
     ldc.i4 1
     ldloc.1
     add
     stloc.1
     br Start
Exit:    
     ret
}

构建运行如下;

我还不是太理解,循环的开始和结束值是不是装入栈;循环变量加1也是在栈上操作;循环中啥也没干,只是输出了循环变量值;bgt、br是跳转语句;有时间继续;

相关推荐
geovindu4 小时前
CSharp: 万年历
开发语言·后端·c#·.net
离陌在学C#12 小时前
C# 异步编程:从 async/await 到 Task 实战指南
开发语言·数据库·c#
用户2986985301416 小时前
PDF 转 HTML 全攻略:三种方法轻松搞定网页转换
c#·html·.net
geovindu16 小时前
CSharp: State Pattern
开发语言·后端·c#·.net·状态模式·行为模式
俊昭喜喜里17 小时前
C#中的decimal
开发语言·c#
JustCheng2 天前
Dispacher(1/2)深入解析-详细使用
c#
CoderIsArt2 天前
C#中UI 线程与 Dispatcher
开发语言·ui·c#
呆呆敲代码的小Y3 天前
【游戏开发】Lua 与 C# 交互原理解析
c#·lua·交互·热更新·lua与c#交互·游戏热更新
用户298698530143 天前
PDF 转纯文本(TXT)免费攻略:轻松提取文字内容
人工智能·后端·c#
呆呆敲代码的小Y3 天前
【游戏开发】C# 中的迭代器
java·开发语言·c#·迭代器