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

相关推荐
Never_Satisfied7 小时前
在c#中,使用windows自带功能将文件夹打包为ZIP
开发语言·windows·c#
Never_Satisfied9 小时前
在c#中,string.replace会替换所有满足条件的子字符串,如何只替换一次
开发语言·c#
观无11 小时前
visionpro的dll导入
c#
Desirediscipline12 小时前
#define _CRT_SECURE_NO_WARNINGS 1
开发语言·数据结构·c++·算法·c#·github·visual studio
蚊子码农14 小时前
算法题解记录-2452距离字典两次编辑以内的单词
开发语言·算法·c#
专注VB编程开发20年15 小时前
c# vb.net Redis 左侧添加,右侧添加(添加到头部,添加到尾部)
redis·c#·.net
kylezhao201915 小时前
C#异步和并发在IO密集场景的典型应用 async/await
开发语言·数据库·c#
游乐码16 小时前
c#索引器
开发语言·c#
Never_Satisfied17 小时前
在c#中,实现把图片文件拖动到pictureBox控件上
开发语言·c#
游乐码18 小时前
c#静态成员
开发语言·c#