首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于IL的有关问题

2012-01-05 
关于IL的问题目前正开始看有关IL的东西,感觉有点迷糊,我写了这样一个简单的类,如下namespaceconsolepro{cl

关于IL的问题
目前正开始看有关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,望高手们帮忙解答。


[解决办法]
能告诉我, 你是怎么看到上面代码的吗?

热点排行