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

相关推荐
地球驾驶员3 分钟前
NX二次开发C#-----NXopen测量两个面的投影距离
c#
猹叉叉(学习版)1 小时前
【ASP.NET CORE】 9. 托管服务
数据库·笔记·后端·c#·asp.net·.netcore
bugcome_com10 小时前
C# 事件(Event)详解及实战示例
c#
CSharp精选营12 小时前
.NET命名之谜:它与C#纠缠20年的关系揭秘
c#·.net·dotnet·csharp
是五月吖12 小时前
【C#】SOLID原则
c#
就是有点傻12 小时前
如何使用简单的服务端去接收数据
c#
人工智能AI技术14 小时前
两会“人工智能+“风口已至:C#开发者用Semantic Kernel搭建企业级Agent的3个实战套路
人工智能·c#
进击的编程阿伟16 小时前
C#开发工程师-面经
面试·c#
缺点内向17 小时前
C#实战:使用Spire.XLS for .NET 将Excel转换为SVG图片
c#·自动化·.net·excel
职豚求职小程序17 小时前
东软集团题库笔试测评系统练习笔试2026新版
大数据·汇编·人工智能