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

相关推荐
人工智能AI技术7 小时前
315曝光AI投毒!用C#构建GEO污染检测与数据安全防护方案
人工智能·c#
金山几座9 小时前
C#学习记录-事件
开发语言·学习·c#
kang0x011 小时前
汇编基础知识练习题
汇编
我是唐青枫13 小时前
C#.NET ReadOnlySequence 深入解析:多段内存遍历与零拷贝协议解析
网络·c#·.net
人工智能AI技术14 小时前
GTC炸场!C#集成NemoClaw企业级Agent实战教程
人工智能·c#
金币闪耀14 小时前
一种winform实时刷新日志内容的方法
c#
Vae_Mars15 小时前
华睿MVP:C#脚本的应用一
笔记·c#
筱璦16 小时前
期货软件开发「启动加载页 / 初始化窗口」
前端·c#·策略模式·期货
qq_3907603916 小时前
简单的线程安全日志记录器
开发语言·数据库·c#
醉酒柴柴17 小时前
word创建样式以后应用于所有新文件
开发语言·学习·c#·word