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

相关推荐
rick9772 小时前
WinForms 父子窗体数据传递的进化之路:从参数注入到事件回传的完美闭环
c#
淡海水2 小时前
C#与常用数据结构源码剖析-全篇导览
开发语言·数据结构·unity·面试·职场和发展·c#
在世修行2 小时前
从零打造 C# 工业视觉检测系统(十五):项目打包部署与进阶展望
开发语言·c#·视觉检测
不正经学生3 小时前
C语言大小端字节序:内存里字节的排列顺序
c语言·开发语言·arm开发·c++·算法·c#
rockey62716 小时前
基于AScript的Lua脚本语言发布啦
c#·.net·lua·script·动态脚本
半亩码田19 小时前
【.NET新特性·第11篇】C# 14 字段属性:告别手写 backing field
java·c#·.net
曹牧19 小时前
C#:问号
前端·数据库·c#
少控科技20 小时前
农场设备管理代码(2)
开发语言·c#
唐青枫21 小时前
别再把命令行参数写成一团:C#.NET System.CommandLine 实战详解
c#·.net
祈禾1 天前
计算机组成原理之编译、汇编、链接、解释
开发语言·汇编·笔记·学习