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

相关推荐
anlog3 小时前
ini文件读取,EXE同目录文件读取
c#·ini
rockey6274 小时前
AScript之编译递归函数
c#·.net·script·动态脚本
Freak嵌入式9 小时前
Pico PIO 汇编语法深度详解:标识符、指令、伪指令全解析
汇编·stm32·单片机·嵌入式硬件·fpga开发·硬件架构
yue00810 小时前
winform控件篇-按钮
c#
DevOpenClub14 小时前
Markdown、HTML 和 PPT 如何稳定交付:文档转换任务的幂等发布流程
开发语言·前端·c#·html·powerpoint
软件黑马王子15 小时前
3.单例模式问题1:构造函数
开发语言·单例模式·c#
软件黑马王子16 小时前
4.单例模式问题2:重复挂载
开发语言·单例模式·c#
夏霞17 小时前
c# 不支持的目标框架 解决方案
开发语言·c#
软件黑马王子17 小时前
5.单例模式问题3:多线程问题
单例模式·前端框架·c#
geovindu17 小时前
CSharp: Template Method Pattern
开发语言·后端·c#·.net·模板方法模式·行为模式