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

相关推荐
第二层皮-合肥11 分钟前
基于C#的工业测试控制软件-总体框架
开发语言·c#
steins_甲乙2 小时前
C# 通过共享内存与 C++ 宿主协同捕获软件窗口
开发语言·c++·c#·内存共享
似水明俊德5 小时前
12-C#.Net-加密解密-学习笔记
笔记·学习·oracle·c#·.net
阿蒙Amon5 小时前
C#常用类库-详解SSH.NET
c#·ssh·.net
似水明俊德6 小时前
11-C#.Net-多线程-Async-Await篇-学习笔记
开发语言·笔记·学习·c#·.net
美团骑手阿豪6 小时前
C#语法:HashSet与List对比,适合场景
unity·c#
wr6 小时前
Modbus 读写转换
c#
公子小六6 小时前
基于.NET的Windows窗体编程之WinForms入门简介
windows·microsoft·c#·.net
CSharp精选营6 小时前
C# 面试高频题:装箱和拆箱是如何影响性能的?
c#·.net·面试题·装箱·拆箱·c#面试题
我是唐青枫7 小时前
C#.NET SpinLock 深入解析:自旋锁原理、使用边界与性能取舍
c#·.net