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

相关推荐
工程师0077 小时前
MQTT 概念详解与 C# 实战
开发语言·c#·mqtt通信
bugcome_com10 小时前
C# 字符串(String)详解与常用操作示例
c#
游乐码11 小时前
c#运算符重载
开发语言·c#
游乐码11 小时前
c#继承的原则
开发语言·c#
游乐码11 小时前
c#内部类和分部类
开发语言·c#
白太岁13 小时前
操作系统开发:(11) RTOS 与 GPOS 的分界线:MMU
c语言·开发语言·汇编·arm开发·系统架构
qq_4542450314 小时前
GraphMindStudio 数据操作层解析:基于 SQLite 的封装与自动化存储
sqlite·c#
HY小海15 小时前
【Unity游戏创作】常见的设计模式
unity·设计模式·c#·游戏程序
专注VB编程开发20年15 小时前
C#,VB.NET如何用GPU进行大量计算,提高效率?
开发语言·c#·.net
qq_4542450316 小时前
开源GraphMindStudio工作流引擎:自动化与AI智能体的理想核心
运维·人工智能·开源·c#·自动化