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

相关推荐
思麟呀7 小时前
在C++基础上理解CSharp-5
开发语言·c++·c#
是星辰吖~8 小时前
WIN32_线程(下)
汇编
z落落11 小时前
C#ToolStrip+StatusStrip 状态栏实时显示系统时间+NotifyIcon系统托盘
开发语言·c#
ctrl_v助手12 小时前
VisionPro (R) QuickBuild相机的连接
服务器·笔记·数码相机·c#
北域码匠13 小时前
奇偶归并排序:并行计算的排序利器
数据结构·算法·c#·排序算法
zhangfeng113313 小时前
国家超算中心 昆山站 异构加速卡1 显存16GB详细配置, 海光 Z100SM HCU
linux·网络·深度学习·c#
是星辰吖~13 小时前
WIN32_线程(上)
汇编
z落落14 小时前
C# WinForm TreeView 树形控件+ListView控件+菜单栏
开发语言·c#
ABprogramming14 小时前
Aspire入门指南
c#·.net
加号314 小时前
【C#】VS2022 传统 ASP.NET Web 服务(.asmx)接口实现指南
前端·c#·asp.net