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

相关推荐
SunflowerCoder1 小时前
EF Core + PostgreSQL 配置表设计踩坑记录:从 23505 到 ChangeTracker 冲突
数据库·postgresql·c#·efcore
阿蒙Amon4 小时前
C#每日面试题-常量和只读变量的区别
java·面试·c#
我是唐青枫4 小时前
C#.NET ConcurrentBag<T> 设计原理与使用场景
c#·.net
大王小生5 小时前
C# CancellationToken
开发语言·c#·token·cancellation
listhi5205 小时前
基于C#实现屏幕放大镜功能
开发语言·c#
该用户已不存在8 小时前
不止是初始化,4个C# 构造函数解析与实例
后端·c#·.net
无风听海11 小时前
深入讲解 C# 中 string 如何支持 CultureInfo
开发语言·c#
wzfj1234511 小时前
FreeRTOS xTaskCreateStatic 详解
开发语言·c#
kylezhao201911 小时前
C# DataGridView 控件使用详解
c#
一个帅气昵称啊11 小时前
C# 14 中的新增功能
开发语言·c#