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

相关推荐
山檐雾13 小时前
OctreeNode
unity·c#·八叉树
Lzh编程小栈14 小时前
数据结构与算法之队列深度解析:循环队列+C 语言硬核实现 + 面试考点全梳理
c语言·开发语言·汇编·数据结构·后端·算法·面试
QfC92C02p16 小时前
C# 中的 Span 和内存:.NET 中的高性能内存处理
java·c#·.net
Yuri X-202117 小时前
VS2022实战测试题——2
程序人生·c#·个人开发·visual studio
公子小六18 小时前
基于.NET的Windows窗体编程之WinForms布局简介
windows·microsoft·c#·.net
zaim118 小时前
计算机的错误计算(二百二十六)
java·python·c#·c·错数·mpmath
William_cl18 小时前
[特殊字符]C# ASP.NET 架构封神之路:分层 + 仓储 + EFCore,写出企业级可维护代码!
架构·c#·asp.net
tq6J5Yg1419 小时前
.NET 10 & C# 14 New Features 新增功能介绍-带修饰符的简单 lambda 参数
开发语言·c#·.net
fe7tQnVan19 小时前
从玩具到生产:基于 ChromaDB 打造工程级 RAG 系统
开发语言·c#
ySq0REx0119 小时前
.NET 10 & C# 14 New Features 新增功能介绍-.NET CLI工具改进
开发语言·c#·.net