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

相关推荐
qq_4542450313 小时前
BuildTemplateGraph 函数深度解析:动态节点图构建的架构设计与核心价值
数据结构·c#
qq_4542450314 小时前
SkeletonFlow:基于组合子逻辑与范畴论的数据流处理框架
数据结构·c#
游乐码14 小时前
c#静态类和静态构造函数
开发语言·c#
net3m3315 小时前
自动分工 现象时,一共有几种可能得权重组合变化,如何确保这些组合的扫描时的不发生组合爆炸
人工智能·c#·ai编程
bugcome_com16 小时前
C# 方法详解:定义、调用与参数传递
c#
光泽雨17 小时前
AppDomain
c#
bugcome_com17 小时前
C# 可空类型(Nullable)详解
c#
大Mod_abfun18 小时前
Socket网络通信教程1(文件传输,IPv4+v6,多客户端管理,重构?)
服务器·网络·c#·socket·vb.net·文件传输
czhc114007566319 小时前
ModBus 218
c#
Never_Satisfied1 天前
在c#中,使用windows自带功能将文件夹打包为ZIP
开发语言·windows·c#