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

相关推荐
Accpdaiyekun31 分钟前
C# 操作mongodb 多次查询快还是使用管道查询速度快
mongodb·c#·lua
Dm_dotnet1 小时前
C#:wpf ui 4.0 是如何实现页面导航的?
c#
圆滚滚肉肉3 小时前
后端MVC(控制器与动作方法的关系)
后端·c#·asp.net·mvc
ajassi20003 小时前
开源 C# .net mvc 开发(六)发送邮件、定时以及CMD编程
linux·开源·c#·mvc
我是唐青枫3 小时前
C#.NET NLog 详解
开发语言·c#·.net
向宇it3 小时前
【unity游戏开发——网络】网络游戏通信方案——强联网游戏(Socket长连接)、 弱联网游戏(HTTP短连接)
网络·http·游戏·unity·c#·编辑器·游戏引擎
一线码农5 小时前
MinHook 如何对 .NET 母体 CoreCLR 进行拦截
c#·.net·代码注入
小老鼠爱大米8 小时前
[C#] WPF - 资源URI
c#·wpf·uri
阿蒙Amon10 天前
《C#图解教程 第5版》深度推荐
开发语言·c#
暖馒10 天前
C#委托与事件的区别
开发语言·c#