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

相关推荐
1-1=044 分钟前
.NET Core 输出日志
c#·.net·.netcore
曹牧1 小时前
C#里引用ActiveX控件
开发语言·c#
宇卿.1 小时前
C#委托详解
开发语言·c#
努力,努力再努力2 小时前
零依赖 C# Office 库到底怎么用——四个场景讲透 Wisdom.Office
c#
2501_930707785 小时前
使用C#代码在 PDF 文档中创建交互操作
pdf·c#·交互
zimoyin15 小时前
在 C# 里嵌入 JavaScript:用 Jint 做可热更新的自动化脚本(从入门到踩坑)
javascript·c#·自动化
小羊没烦恼!17 小时前
异步编程:线程概述及使用
java·开发语言·mysql·算法·c#
c#上位机19 小时前
C#上位机项目实战——exe项目调试更改dll中源代码
开发语言·c#
淡海水20 小时前
06-02-源码-增量标记算法实现
算法·unity·c#·gc
淡海水21 小时前
06-01-源码-Incremental GC总览与设计
unity·c#·gc