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

相关推荐
Jeremy爱编码6 小时前
实现 Trie (前缀树)
开发语言·c#
烛阴6 小时前
C# 正则表达式(4):分支与回溯引用
前端·正则表达式·c#
huluang12 小时前
Word文档批注智能克隆系统的设计与实现
开发语言·c#·word
kylezhao201913 小时前
C#上位机开发数据持久化:excel报表导入导出
开发语言·c#·excel
wangnaisheng15 小时前
【C#】RocketMQ、Redis的使用
c#
阿蒙Amon15 小时前
C#每日面试题-接口和抽象类的区别
开发语言·c#
ejjdhdjdjdjdjjsl16 小时前
深入理解C#泛型:从方法到约束
c#
bugcome_com17 小时前
WPF 核心布局控件全解析:从 Grid 到 UniformGrid 的实战应用
c#·wpf
wangnaisheng17 小时前
Intel IPP 图像处理相关函数
c++·c#·图像
阿蒙Amon18 小时前
C#每日面试题-简述可空类型
microsoft·面试·c#