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

相关推荐
UIU1143 小时前
补码运算与整数溢出(上
学习·c#·补码·补码运算
曹牧4 小时前
C#:模态对话框
开发语言·c#
咕白m6254 小时前
C# 如何限制 PDF 复制、打印权限?
c#·.net
yume_sibai5 小时前
正则表达式完全指南(基础语法 + 实战应用 + 性能优化 + 最佳实践)
开发语言·正则表达式·c#
Nil2085 小时前
leetcode 79单词搜索
开发语言·c#
神仙别闹5 小时前
基于C#实现(WinForm)文件管理系统
java·开发语言·c#
reasonsummer6 小时前
【办公类-146-07】20260906《总园大班6个班级四大教育》(优化版:标题excle+复制AI文字+Python占位符录入)
人工智能·python·c#
玖玥拾6 小时前
Lua 基础语法(六)xLua Lua 调用 C# 交互
开发语言·unity·c#·lua
戌中横8 小时前
数据持久化——PlayerPrefs
c#·数据持久化
曹牧15 小时前
C#:窗体Topmost与获取输入焦点
c#