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

相关推荐
临风细雨31 分钟前
从 Bun 的 Rust 重写,看 C# 如何重建 AI 基础设施层
人工智能·rust·c#
吴可可1231 小时前
C# CAD二次开发自定义实体实现
c#
z落落2 小时前
C# WinForm 线程池与事件等待+进度条暂停恢复实战案例
开发语言·c#
酷酷的身影4 小时前
Managers/APConfigManager.cs
开发语言·ui·c#
贾斯汀frank16 小时前
C# 15 类型系统改进:Union Types
开发语言·windows·c#
时代的狂18 小时前
如何理解 C# 的 async 和 await
c#·.netcore·async·await
xiaoshuaishuai821 小时前
C# AI实现PR处理、单元测试
开发语言·c#·log4j
LONGZHIQIN21 小时前
C#基础复习笔记
开发语言·笔记·c#
学逆向的1 天前
汇编——数据存储模式
开发语言·汇编·网络安全
时代的狂1 天前
如何理解 C#/.NET 的依赖注入与生命周期
c#·.net·依赖注入·控制反转