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

相关推荐
周杰伦fans2 小时前
C# 踩坑 CS8370:Switch Expression 在 C# 7.3 不可用及三种解决方案
c#
z落落4 小时前
C# ToCharArray + foreach遍历 + String与StringBuilder
开发语言·c#
xiaoshuaishuai85 小时前
C# AvaloniaUI动态显示图片
开发语言·c#
是星辰吖~6 小时前
X86反汇编:透视之眼_反编译特训(1-2)
汇编
csdn_aspnet8 小时前
EasyModbus 与 C# 集成
c#·modbus·easymodbus
JaydenAI10 小时前
[MAF预定义ChatClient中间件-06]利用ImageGeneratingChatClient开发专业图片生成Agent
ai·c#·agent·agent管道·chatclient中间件·chatclient管道
csdn_aspnet11 小时前
Modbus TCP C# 客户端程序
服务器·网络·tcp/ip·c#
0x000712 小时前
译 Anders Hejlsberg 谈 C# 与 .NET
开发语言·c#·.net
Xin_ye1008612 小时前
C# 零基础到精通教程 - 第十七章:前端集成——Blazor 基础
开发语言·c#