您的位置:程序门 -> .net技术 -> c#



关于il的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于il的问题[已结贴,结贴人:fortner]
发表于: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,望高手们帮忙解答。
发表于:2007-03-28 08:26:191楼 得分:0
没人帮忙回答下吗?   -_-
发表于:2007-03-28 08:26:202楼 得分:0
没人帮忙回答下吗?   -_-
发表于:2007-03-28 09:52:373楼 得分:20
能告诉我,   你是怎么看到上面代码的吗?
发表于:2007-03-28 17:13:004楼 得分:0
用ildasm.exe   ,   2.0包自带的.........
参数0查到了,好像是this指针


快速检索

最新资讯
热门点击