了解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: Wordcloud
开发语言·后端·c#·.net·.netcore·词云
geovindu5 小时前
CSharp: Command Pattern
开发语言·后端·c#·.net·.netcore·命令模式·行为模式
格林威8 小时前
C# 相机图像阴影校正:使用OpenCvSharp实现工业相机阴影平场校正功能
人工智能·数码相机·opencv·计算机视觉·c#·机器视觉·工业相机
俊昭喜喜里9 小时前
c#中的构造函数
开发语言·数据库·c#
hahaha60169 小时前
HLS高层次综合设计--axi之burst纠偏
开发语言·算法·fpga开发·c#
点心的游戏开发世界18 小时前
Unity C# 脚本学习笔记:命名空间与 using
学习·unity·c#
淡海水19 小时前
07-04-并发-ConcurrentBag-T-工作窃取WorkStealing算法
开发语言·算法·c#·bag·concurrent·workstealing
点心的游戏开发世界19 小时前
Unity C# 脚本学习笔记:泛型
学习·unity·c#
公子小六1 天前
基于.NET的Windows窗体编程之WinForms滑块与上下控件
windows·microsoft·c#·.net·winforms
曹牧1 天前
C#:文本文件读取
服务器·前端·c#