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

相关推荐
iCxhust14 小时前
C#进程管理程序
开发语言·汇编·stm32·单片机·c#·微机原理
ceclar12316 小时前
C# 的任务并行库(TPL)
开发语言·c#·.net
hhcgchpspk16 小时前
汇编语言传递数据和地址的误区
汇编·笔记·nasm·masm
xiaoshuaishuai816 小时前
C# 委托与事件
开发语言·c#
Song_da_da_17 小时前
C# 接口(Interface)深度解析:规范、解耦与灵活扩展
开发语言·c#
政沅同学17 小时前
基于 C# WPF + HALCON 的工业视觉算法工具框架(开源)
开发语言·c#·wpf
iCxhust17 小时前
MTK8088单板机制作(一)时钟电路
汇编·单片机·嵌入式硬件·微机原理·8088单板机
影寂ldy17 小时前
C#WinForm 窗体基础(入口、部分类、属性、生命周期事件)
开发语言·c#
ceclar12318 小时前
C#异步编程async与await
c#·.net