IL代码,
.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 4stloc.0 //Upper limit of the Loop, total 5 ldc.i4 0 stloc.1 //Initialize the Starting of loop Start: //Check if the Counter exceedsldloc.1 ldloc.0 bgt Exit //If Second variable exceeds the first variable, then exitldloc.1call void [mscorlib]System.Console::WriteLine(int32)//Increase the Counterldc.i4 1ldloc.1addstloc.1br Start
Exit: ret
}
构建运行如下;
我还不是太理解,循环的开始和结束值是不是装入栈;循环变量加1也是在栈上操作;循环中啥也没干,只是输出了循环变量值;bgt、br是跳转语句;有时间继续;