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

相关推荐
吴可可12310 小时前
C++与C#版Teigha样条离散化差异解析
c++·算法·c#
say_fall10 小时前
8086汇编程序设计_从基础到实战
开发语言·汇编·8086
JaydenAI10 小时前
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱(Token)省时间
ai·c#·agent·caching·maf·chatclient中间件
曹牧10 小时前
C#:List<T>.ForEach(Action<T> action)
c#
海盗123410 小时前
C#中PDF操作-QuestPDF介绍和使用教程
pdf·c#
影寂ldy10 小时前
C#数组的高级方法
开发语言·c#
曹牧10 小时前
C#:基类中定义泛型方法
java·开发语言·c#
游乐码10 小时前
c#基础(七)延迟函数
开发语言·unity·c#·游戏引擎
魔法阵维护师10 小时前
从零开发游戏需要学习的c#模块,第二十六章(多种敌人与基础 AI)
学习·游戏·c#
思麟呀10 小时前
在C++基础上理解CSharp-4
开发语言·jvm·c++·c#