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

相关推荐
hixiong1235 小时前
TensorRT转换工具分享
人工智能·计算机视觉·ai·c#
莫生灬灬7 小时前
DY联系人聊天Web面板支持获取联系人/聊天记录/发送消息
前端·chrome·websocket·c#
逝水无殇8 小时前
C# 多态性详解
开发语言·后端·c#
逝水无殇8 小时前
C# 继承(Inheritance)详解
开发语言·后端·c#
asdzx6711 小时前
C# 通过模板生成 Word 文档:文本与图片占位符替换完整攻略
开发语言·c#·word
影寂ldy11 小时前
C# 泛型协变与逆变
windows·microsoft·c#
F20226974861 天前
西门子 PLC 与 C# 通信
开发语言·c#
吴可可1231 天前
C#实现CAD框选闭合图元外偏移1毫米
c#
꒰ঌ 安卓开发໒꒱1 天前
.NET CAP入门到入土
后端·c#·.net
想你依然心痛1 天前
自定义RTOS内核:从零实现上下文切换与任务调度——汇编、PendSV
java·开发语言·汇编·pendsv