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

相关推荐
颜x小4 小时前
[C#] C++与c#语法对比
开发语言·c++·c#
weixin_423652134 小时前
C#使用JObject
开发语言·c#
Z5998178415 小时前
c#软件开发学习笔记--Modbus-RTU通讯
笔记·学习·c#
用户298698530149 小时前
在 PC 上将 HTML 转换为 PDF 的3种有效方法
人工智能·c#·html
Rotion_深11 小时前
C# 设计TCP Server
开发语言·tcp/ip·c#
csdn_aspnet12 小时前
C# 从凸包中删除点(Deleting points from Convex Hull)
开发语言·c#
wechatbot88812 小时前
解决企业微信官方 API 短板:iPad 协议全功能对接方案
java·汇编·windows·http·微信·企业微信
czhc114007566313 小时前
7.28 从“图形状态切换“理解 Parse 与状态驱动模式
c#
逻极15 小时前
C# 从入门到精通:现代云原生与AI应用开发实战
ai·云原生·c#·.net
geovindu1 天前
CSharp: Breadth First Search Algorithm and Depth First Search Algorithm
开发语言·后端·算法·c#·.net·搜索算法