| 发表于:2007-03-27 17:28:48 楼主 |
目前正开始看有关il的东西,感觉有点迷糊,我写了这样一个简单的类,如下 namespace consolepro { class color { protected int red; protected int green; protected int blue; public color() { this.red = 0; this.green = 127; this.blue = 225; } public void getrgb(ref int red,ref int green,ref int blue) { red = this.red; green = this.green; blue = this.blue; } } } 然后进行build,得到.exe文件后察看getrgb函数部分的il代码,如下: .method public hidebysig instance void getrgb(int32& red, int32& green, int32& blue) cil managed { // code size 26 (0x1a) .maxstack 8 il_0000: nop il_0001: ldarg.1 il_0002: ldarg.0 il_0003: ldfld int32 consolepro.color::red il_0008: stind.i4 il_0009: ldarg.2 il_000a: ldarg.0 il_000b: ldfld int32 consolepro.color::green il_0010: stind.i4 il_0011: ldarg.3 il_0012: ldarg.0 il_0013: ldfld int32 consolepro.color::blue il_0018: stind.i4 il_0019: ret } // end of method color::getrgb 问题如下: 1.stack 的最大值为8,是说最多压了8次的栈还是9次,如果是8次,为什么会有9次的ld行为? 2.ldarg.0查msdn为压入方法的第一个参数,这个参数是什么,难道是函数入口地址?如果不是函数入口地址的话为什么会有ldarg.3的行为,方法只有三个参数,但出现了第4个参数压栈行为。 3.sting.i4将int写入一个地址,int值应该是ldfld压入的东西,那么地址在哪?是两次ldarg行为的总值?ldarg.0压的是基地址而ldarg.1压的是偏移量? 平台用的2.0,望高手们帮忙解答。 |
|
|
|
|