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

相关推荐
猿长大人14 小时前
C# | MediatR 入门指南:后端架构解耦
分布式·后端·架构·c#·.net
回忆2012初秋14 小时前
C# 中的 EAP:基于事件的异步编程全面指南(一)
开发语言·c#
曹牧15 小时前
C#:Type
开发语言·c#
用户37215742613516 小时前
C# 如何在 Excel 中创建下拉列表:3 种常见数据源实现方式
c#
czhc114007566316 小时前
工业视觉检测中的通用设计模式与技术笔记
c#
明如正午17 小时前
【C#】volatile 关键字深度解析:为什么我的停止按钮有时失灵?
c#
猿长大人1 天前
C# | JSON 序列化中的多态接口处理:基于 Attribute 实现精准 $type 控制
c#·json
一位狮子座的程序员1 天前
如何用RAG解决AI智能体的知识盲区?
开发语言·c#
Nemo_XP2 天前
C# gridlookupedit选中内容重复还原操作
服务器·前端·c#