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

相关推荐
何以解忧唯有撸码6 小时前
c# + YOLODotNet+OpenCVSharp 实现物品轨迹追踪
计算机视觉·c#·winform·yolov8·opencvsharp
阿松爱学习16 小时前
【Unity开发】局部区域截图功能实现
unity·c#
zhanghaha131416 小时前
C# 系列教程_1 基础语法篇(面向新手系统教程)
开发语言·c#
昂好的day17 小时前
固高运动控制卡实战(下):点位运动与直线/圆弧插补 API 详解
开发语言·c#
水饺编程18 小时前
第2章:Linux 基础,解压缩【.tar.gz】压缩包
linux·c语言·汇编
淡海水21 小时前
08-02-优化-LINQ与函数式编程的GC代价
unity·c#·.netcore·linq·gc
sali-tec1 天前
C# 基于OpenCv的视觉工作流-章114-视觉与http通讯
图像处理·人工智能·opencv·计算机视觉·c#
波力海苔夹心脆6751 天前
C# 委托与事件详解:委托声明、Action/Func、多播、event 与 EventHandler 入门教程
开发语言·c#·.net·上位机·委托·事件
水饺编程2 天前
第2章:Linux 基础,exit 命令
linux·c语言·汇编
水饺编程2 天前
第2章:Linux 基础,删除用户
linux·c语言·汇编