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

相关推荐
曹牧13 小时前
C#:函数参数指定默认值
开发语言·c#
李高钢14 小时前
WPF MVVM Light(三):RelayCommand 命令与 Messenger 消息
前端·c#·wpf
曹牧19 小时前
C#:字符串做20位截断
开发语言·c#
离陌在学C#1 天前
C# 事件(Event)详解:从概念到实战
开发语言·c#
rockey6271 天前
C#脚本引擎之AScript与Flee对比
c#·.net·script·eval·动态脚本
zjnlswd2 天前
C#学习笔记4
笔记·学习·c#
曹牧2 天前
C#:List<string>特定格式输出
windows·c#
Z5998178412 天前
c#软件开发学习笔记--Modbus-TCP/UDP网口通讯
笔记·学习·c#
曹牧2 天前
C#:取的多个药品批准文号中的一个
c#
用户298698530142 天前
3 种方法,轻松将 PowerPoint 转换为 PDF 格式
人工智能·后端·c#