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

相关推荐
DevOpenClub2 小时前
Markdown、HTML 和 PPT 如何稳定交付:文档转换任务的幂等发布流程
开发语言·前端·c#·html·powerpoint
软件黑马王子3 小时前
3.单例模式问题1:构造函数
开发语言·单例模式·c#
软件黑马王子4 小时前
4.单例模式问题2:重复挂载
开发语言·单例模式·c#
夏霞5 小时前
c# 不支持的目标框架 解决方案
开发语言·c#
软件黑马王子5 小时前
5.单例模式问题3:多线程问题
单例模式·前端框架·c#
geovindu5 小时前
CSharp: Template Method Pattern
开发语言·后端·c#·.net·模板方法模式·行为模式
CSDN_RTKLIB6 小时前
SetImpliedSelection
c#
软件黑马王子6 小时前
1.non-MonoBehaviour 单例模式泛型基类
unity·前端框架·c#
高彬7 小时前
SAP ECC6.0 对接 C# web Services服务
开发语言·前端·c#·sap
半亩码田7 小时前
C#转Python第4.4篇:JSON 处理:json 模块 vs System.Text.Json
python·c#·json