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

相关推荐
火星papa3 小时前
C# 阻塞队列(BlockingCollection)
c#·queue·阻塞队列
OctShop大型商城源码8 小时前
.NET线上商城源码_C#商城源码_技术赋能下的电商新生态
开发语言·c#·.net·商城系统源码
hixiong12311 小时前
C#文件目录结构生成工具
开发语言·c#
滴滴答答哒13 小时前
# SqlSugar 差异日志功能实现
c#
顾温14 小时前
协程结束——实测
开发语言·unity·c#
Byron Loong14 小时前
【逆向】AT Hook 与 Inline Hook 对比
c语言·汇编·c++
唐青枫16 小时前
C#.NET YARP 详解:用 ASP.NET Core 打造高性能反向代理网关
c#·.net
asdzx6716 小时前
告别手工复制:用 C# 轻松合并多份 Word
c#·word
步步为营DotNet17 小时前
NET 11 中 C# 14 新特性在云原生微服务架构的深度实践
云原生·架构·c#
不会编程的懒洋洋18 小时前
WPF 性能优化+异步+渲染
开发语言·笔记·性能优化·c#·wpf·图形渲染·线程