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

相关推荐
LibraJM6 小时前
一种适合程序员的 Agent 协作方式的实践
c#·copilot·agents
旋律翼211 小时前
Qt Bridges for C# 深度技术解析
开发语言·qt·c#
吴可可12312 小时前
判断多段线方向的鞋带公式法
c#
qq_4542450312 小时前
BasicMethod.Map 设计框架:8 个并行基础模块的数学根基与实现
数据结构·算法·c#
Byron Loong13 小时前
【c#】Bitmap释放之 大象与蚊子
开发语言·c#
临风细雨14 小时前
从 Bun 的 Rust 重写,看 C# 如何重建 AI 基础设施层
人工智能·rust·c#
吴可可12315 小时前
C# CAD二次开发自定义实体实现
c#
z落落16 小时前
C# WinForm 线程池与事件等待+进度条暂停恢复实战案例
开发语言·c#
酷酷的身影18 小时前
Managers/APConfigManager.cs
开发语言·ui·c#
贾斯汀frank1 天前
C# 15 类型系统改进:Union Types
开发语言·windows·c#