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

相关推荐
暗暗别做白日梦1 小时前
Pulsar 消息同步机制
c#·linq
海盗12341 小时前
微软技术周报——2026-07-22
microsoft·c#·.net
海盗12341 小时前
微软技术日报 ——2026-07-21
microsoft·c#·.net
-银雾鸢尾-1 小时前
C#中的泛型约束
开发语言·c#
WWJA王文举1 小时前
单片机参数如何掉电保存:Flash、EEPROM和配置存储完整设计
数据库·stm32·mongodb·c#
czhc11400756633 小时前
722:零侵入;DBG;
c#
-银雾鸢尾-12 小时前
C#中的StringBuilder相关方法
开发语言·c#
-银雾鸢尾-12 小时前
C#中结构体与类的区别;抽象类与接口的区别
开发语言·c#
心平气和量大福大16 小时前
C#-WPF-Window主窗体
开发语言·c#·wpf
白露与泡影16 小时前
Arthas 实战指南:从方法耗时定位到 JVM 变量热修改
服务器·jvm·c#