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

相关推荐
yong99909 小时前
C# 实时查看硬件使用率(CPU 内存 硬盘 网络)
开发语言·网络·c#
神仙别闹11 小时前
基于 C# OpenPGP 的文件管理系统
开发语言·c#
海盗123413 小时前
C#在Distinct()中使用IEqualityComparer<T>
开发语言·c#
呼Lu噜15 小时前
基于C#的ASP.NET Core中分析async、await的使用场景
数据库·c#·asp.net
等故意19 小时前
C# 工业视觉上位机开发心得分享
开发语言·数码相机·c#·视觉检测
时光追逐者19 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 70 期(2026年5.01-5.10)
c#·.net·.netcore
莫生灬灬19 小时前
ElementUI封装 共91个组件 支持易语言/火山/C#/Python
开发语言·c++·python·ui·elementui·c#
huaqianzkh20 小时前
POCO = Plain Old CLR/CSharp Object
c#
这猪好帅20 小时前
协程原理与实现
汇编