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

相关推荐
m5655bj15 小时前
通过 C# 将 RTF 文档转换为图片
开发语言·c#
MM_MS16 小时前
WinForm+C#小案例--->写一个记事本程序
开发语言·计算机视觉·c#·visual studio
fengye20716116 小时前
板凳————————————(枯藤 )vs2019+win10
汇编
浪客川18 小时前
高效日志分离器:一键筛选关键信息
开发语言·windows·c#
小熊熊知识库19 小时前
C# EF.core 介绍以及高性能使用
开发语言·c#
T.Ree.19 小时前
汇编_movsd和stosd
汇编
雨疏风骤124019 小时前
【FreeRTOS】任务、任务状态
开发语言·stm32·c#·rtos
️公子21 小时前
传奇游戏集成系统
游戏·c#
玩泥巴的21 小时前
强的飞起的 Roslyn 编译时代码生成,实现抽象类继承与依赖注入的自动化配置
c#·.net·代码生成·roslyn
mudtools21 小时前
强的飞起的 Roslyn 编译时代码生成,实现抽象类继承与依赖注入的自动化配置
c#·.net