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

相关推荐
宝桥南山8 小时前
.NET 11 - 尝试一下Blazor中的新特性SupplyParameterFromTempData
microsoft·微软·c#·asp.net·.net·.netcore
1-1=09 小时前
C# 中 Lambda、Linq 与 Expression
c#·linq
zhanghaha131410 小时前
C# 系列教程_7 判断语句(分支)保姆级精讲
开发语言·c#
zhanghaha131410 小时前
C# 系列教程_8 循环语句 保姆级精讲(面向新手)
开发语言·c#
rockey62720 小时前
AScript之LINQ扩展
c#·.net·script·动态脚本
1-1=01 天前
C# 委托与事件
开发语言·c#
1-1=01 天前
C# 特性(Attribute)
c#·.net·.netcore
淡海水2 天前
10-01-互操作-C#与C++边界的内存管理
unity·c#·游戏引擎·.netcore·gc
WarPigs2 天前
C#把byte[]以十六进制打印,带分割符
c#
暴走约伯2 天前
【VFX工具链源码拆解 04】拯救丢失的绑定:Timeline 一键克隆与层级相对路径重映射算法
unity·c#·游戏引擎·硬件工程