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

相关推荐
枳实-叶14 小时前
【Linux驱动开发】第23天:spi_driver 的 probe / remove 函数实现规范
linux·驱动开发·c#
长明15 小时前
C#项目组织与概念梳理
后端·c#
迷路爸爸18015 小时前
Python collections 入门+实战
windows·python·c#·collections·dict
csdn_aspnet15 小时前
C# 截取或匹配字符串内包含指定字符的一些方法
c#·字符串·分割·string·匹配·截取
Rotion_深16 小时前
C# 值类型与引用类型 详解
开发语言·jvm·c#
影寂ldy1 天前
C# try-catch 异常处理全套笔记
服务器·数据库·c#
TeamDev1 天前
JxBrowser 9.3.0 版本发布啦!
java·后端·c#·混合应用·jxbrowser·浏览器控件·异步媒体设备
梦帮科技1 天前
UE5 GAS 实战:用 Gameplay Ability System 搭建「赛博修真」境界与技能体系
c++·人工智能·python·ue5·c#
北域码匠1 天前
RIPEMD-128哈希算法深度解析
c#·密码学·哈希算法·加密算法·消息摘要·ripemd-128·原生实现
csdn_aspnet1 天前
C# 截取或匹配字符串内包含指定字符
c#·字符串·正则·string·匹配·截取