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

相关推荐
曹牧1 小时前
C#:List<string>特定格式输出
windows·c#
Z5998178412 小时前
c#软件开发学习笔记--Modbus-TCP/UDP网口通讯
笔记·学习·c#
曹牧4 小时前
C#:取的多个药品批准文号中的一个
c#
用户298698530147 小时前
3 种方法,轻松将 PowerPoint 转换为 PDF 格式
人工智能·后端·c#
KindSuper_liu7 小时前
HybridCLR DHE及MetaVersion工作流核心概念
c#
淡海水8 小时前
01-08-运行时-虚方法分派与接口调用的底层实现
linux·windows·microsoft·c#·虚方法·vtable·vsd
李高钢8 小时前
C# WPF Prism 进阶(三):导航(Navigation)深入
开发语言·c#·wpf
我是苏苏9 小时前
C#基础:不写for循环的五种方式
数据结构·算法·c#
six_1 天前
C# 上位机(持续更新中)
前端·面试·c#
吴可可1231 天前
多段线扩展数据的应用场景
c#