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

相关推荐
水饺编程10 小时前
第2章:Linux 基础,exit 命令
linux·c语言·汇编
水饺编程14 小时前
第2章:Linux 基础,删除用户
linux·c语言·汇编
He BianGu14 小时前
【笔记】C# 中BindingFlags的详细作用
笔记·c#
?abc!14 小时前
(贪心)621. 任务调度器
java·前端·c#
开开心心就好17 小时前
电脑小说阅读器,支持朗读和自定义皮肤
服务器·开发语言·javascript·算法·pdf·c#·音视频
淡海水17 小时前
07-06-源码-.NET Core GC的极致优化技术
unity·架构·c#·.netcore·gc·1024程序员节
万化冥合18 小时前
怎么批量把 Word 转 PDF?
python·pdf·c#·word
淡海水1 天前
07-02-源码-.NET Core GC分配路径
算法·unity·c#·.netcore·gc·1024程序员节
吴可可1231 天前
C#调用摄像头拍照的三种API方案
c#
Msir_Modern2 天前
Noita 元胞沙盒笔记
算法·unity·c#·游戏引擎·元胞自动机