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

相关推荐
aini_lovee1 小时前
C# 快递单打印系统(万能套打系统)
开发语言·c#
白菜上路1 小时前
C# Serilog.AspNetCore基本使用
c#·serilog
小白不白1112 小时前
C# WinForm 与 VP 二次开发
开发语言·c#
SunnyDays10113 小时前
如何使用 C# 自动调整 Excel 行高和列宽
开发语言·c#·excel
itgather4 小时前
OfficeExcel — Word / Excel DLL 验证台功能介绍
c#·word·excel
云中小生4 小时前
Scrutor:.NET 依赖注入自动化的优雅实现
c#·.net
郝亚军4 小时前
Visual Studio 2022项目中的.sln是什么?
c++·c#·visual studio
jghhh014 小时前
C# 图片水印工具(支持9个位置)
数据库·microsoft·c#
咸鱼翻身小阿橙5 小时前
C# WinForms 控件学习项目
开发语言·学习·c#
JaydenAI5 小时前
[MAF预定义Agent中间件-03]FunctionInvocationDelegatingAgent:将AOP引入函数调用
ai·c#·agent·aop·maf