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

相关推荐
农村小镇哥15 小时前
C#中的字符串格式化
服务器·开发语言·c#
czhc114007566319 小时前
719:StartPoint;Margin;ResourceDictionar;Component.model;lds;
c#
-银雾鸢尾-21 小时前
C#中的万物之父——Object类
开发语言·c#
水晶石NSIS专栏21 小时前
Geek_Studio - 安卓终端调试工作台
android·c#·apk签名·coloros主题
-银雾鸢尾-21 小时前
C#中的继承
开发语言·c#
吴可可1231 天前
C#AutoCAD二次开发打断多段线
c#
-银雾鸢尾-1 天前
里氏替换原则
开发语言·c#·里氏替换原则
-银雾鸢尾-2 天前
C#中的索引器
开发语言·c#
en.en..2 天前
冒泡排序与选择排序完整对比解析
开发语言·数据结构·算法·c#·排序算法