了解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是跳转语句;有时间继续;

相关推荐
1314lay_10076 小时前
C# 点击一次api,限流中间件但是X-Rate-Limit-Remaining剩余数量减少2
visualstudio·c#
“抚琴”的人6 小时前
C#上位机工厂模式
开发语言·c#
工程师0079 小时前
C#中的AutoUpdater自动更新类
开发语言·c#·自动更新开源库·autoupdate
切糕师学AI10 小时前
ARM 中的 SVC 监管调用(Supervisor Call)
linux·c语言·汇编·arm开发
曹牧11 小时前
C#:Obsolete
开发语言·c#
我是苏苏11 小时前
Web开发:使用C#的System.Drawing.Common将png图片转化为icon图片
开发语言·c#
阿蒙Amon11 小时前
C#每日面试题-is和as的区别
java·开发语言·c#
阿蒙Amon11 小时前
C#每日面试题-简述泛型约束
java·开发语言·c#
ベadvance courageouslyミ12 小时前
硬件基础中断
汇编·硬件·中断
1314lay_100713 小时前
C# .Net 7.0 Core添加日志可视化
visualstudio·c#·.net·.netcore