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

相关推荐
祀爱15 小时前
Asp.net core+ Layui 项目中编辑按钮传递数据的方法
前端·c#·asp.net·layui
雪豹阿伟20 小时前
C# —— 上位机行业解析与完整学习规划
c#·上位机
一念春风21 小时前
记事本(C#)
开发语言·c#
wangl_9221 小时前
初探 C# 15 的 Union Types
java·开发语言·算法·c#·.net·.net core
雪豹阿伟1 天前
C# 与 .NET 生态系统概述
c#·上位机
puamac1 天前
c#打开cmd然后输入claude
stm32·单片机·c#
雪豹阿伟1 天前
1.C# —— 项目结构、变量、数据类型与枚举
c#·上位机
雪豹阿伟1 天前
C# —— Visual Studio 2026 安装教程
c#·上位机
FuckPatience1 天前
C# 引用dll没用,显示没有对应的类名称
c#