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

相关推荐
阿松爱学习6 小时前
【Unity开发】Unity长截图功能实现
unity·c#·游戏引擎
水饺编程8 小时前
第2章:Linux 基础,在 root 中创建用户账号
linux·c语言·汇编·1024程序员节
_oP_i9 小时前
Windows 11 家庭中文版 25H2
c#
unicrom_深圳市由你创科技9 小时前
电池化成曲线MES追溯:关键点提取与验证
c#
老王IT9 小时前
C#语言基础语法介绍
开发语言·c#
人丰10 小时前
一次生产卡顿复盘:BI 数据抽取引发 PostgreSQL 长事务事故
数据库·c#
一个风轻云淡11 小时前
从 int $0x80 到 iret:用 gdb 把 getpid 走一遍
linux·c语言·开发语言·汇编
淡海水12 小时前
07-01-源码-.NET Core GC总览与架构
unity·架构·c#·.netcore·gc
weixin_4166600714 小时前
Mermaid流程图导出到Word:SVG、PNG与清晰度如何选择?
开发语言·c#
公子小六17 小时前
基于.NET的Windows窗体编程之WinForms自定义控件(3)
windows·c#·.net·音视频·winforms