了解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#通讯(上位机)常用知识点
开发语言·c#·通讯·上位机开发
武藤一雄1 天前
C#:nameof 运算符全指南
开发语言·microsoft·c#·.net·.netcore
CSharp精选营2 天前
聊一聊 C# 中的闭包陷阱:foreach 循环的坑你还记得吗?
c#·foreach·循环·for循环
月巴月巴白勺合鸟月半2 天前
FHIR 的使用
人工智能·c#·fhir
公子小六2 天前
基于.NET的Windows窗体编程之WinForms控件简介
windows·microsoft·c#·.net
观无2 天前
mysql5.7下载地址
c#
武藤一雄2 天前
C# 核心技术解析:Parse vs TryParse 实战指南
开发语言·windows·microsoft·微软·c#·.netcore
代数狂人2 天前
在Godot中应用面向对象原则:C#脚本实践
c#·游戏引擎·godot
斌味代码2 天前
RAG 实战:用 LangChain + DeepSeek 搭建企业私有知识库问答系统
开发语言·langchain·c#
陌上花开缓缓归以2 天前
mips u-boot如何在汇编中添加调式打印
汇编