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

相关推荐
爱吃苹果的日记本9 小时前
数据结构第一课
c语言·数据结构·数据库·学习·c#
唐青枫11 小时前
C#.NET PInvoke 深入解析:封送、内存布局与原生互操作实战
c#·.net
软件黑马王子14 小时前
24.Editor 资源加载:主要作用和基本原理
开发语言·前端框架·c#
慧都小妮子14 小时前
用 Python 批量把 PDF 参考文献排成 MLA 格式:Spire.Doc for Python 实战
python·pdf·c#·spire.doc·mla格式·参考文献排版·pdf批量处理
UIU11418 小时前
补码运算与整数溢出(上
学习·c#·补码·补码运算
曹牧19 小时前
C#:模态对话框
开发语言·c#
咕白m62520 小时前
C# 如何限制 PDF 复制、打印权限?
c#·.net
yume_sibai20 小时前
正则表达式完全指南(基础语法 + 实战应用 + 性能优化 + 最佳实践)
开发语言·正则表达式·c#
Nil20820 小时前
leetcode 79单词搜索
开发语言·c#
神仙别闹20 小时前
基于C#实现(WinForm)文件管理系统
java·开发语言·c#