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

相关推荐
吴可可12315 小时前
C#实现CAD框选闭合图元外偏移1毫米
c#
꒰ঌ 安卓开发໒꒱15 小时前
.NET CAP入门到入土
后端·c#·.net
想你依然心痛16 小时前
自定义RTOS内核:从零实现上下文切换与任务调度——汇编、PendSV
java·开发语言·汇编·pendsv
hai31524754316 小时前
九章空间几何对照直译法:通用芯片 / 定制专用芯片 编译适配规则
linux·汇编·bash
逝水无殇19 小时前
C# 枚举(Enum)详解
开发语言·后端·c#
Java面试题总结21 小时前
C# 源生成器使用方法
windows·ui·c#
影寂ldy21 小时前
C# WinForms 窗体继承
开发语言·c#
苍狼唤1 天前
WinForm练习知识补充(多线程)
c#
逝水无殇2 天前
C# 字符串(String)详解
开发语言·后端·c#
小巧的砖头2 天前
C#会重蹈覆辙吗?系列之2:反射及元数据的性能问题
开发语言·前端·c#