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

相关推荐
nnsix2 小时前
C# 字符串 根据换行符分割
开发语言·c#
吴可可1232 小时前
C# Exception命名空间冲突解决方案
c#
佚泽4 小时前
C# webApi学习笔记
笔记·学习·c#
魔法阵维护师5 小时前
从零开发游戏需要学习的c#模块,第二十四章(瓦片地图 —— 让世界有墙)
学习·游戏·c#
吴可可1235 小时前
C#中括号报错“应输入标识符”原因解析
c#
lingxiao168887 小时前
智慧停车场(SmartParking)
c#·自动化·wpf
yngsqq8 小时前
加载dll失败
c#
吴可可12311 小时前
C#中is运算符的正确用法
c#