因为这些IL代码我看到的更多,所以我想学习如何正确地解释它们。
我找不到像C#编译器这样的文档或其他文档,所以我认为在我学习了下面这些常用的文档之后,我可以很好地处理剩下的事情:
下面是一些示例IL代码,其中包含我需要知道的内容:
示例1:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 15 (0xf)
.maxstack 1
.locals init ([0] class EnumReflection.DerivedClass derivedClass)
IL_0000: nop
IL_0001: newobj instance void EnumReflection.DerivedClass::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: callvirt instance void EnumReflection.DerivedClass::WriteOutput()
IL_000d: nop
IL_000e: ret
} // end of method Program::Main
示例2:
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 38 (0x26)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldstr "Hello"
IL_0006: stfld string EnumReflection.DerivedClass::hello
IL_000b: ldarg.0
IL_000c: ldstr "World"
IL_0011: stfld string EnumReflection.DerivedClass::world
IL_0016: ldarg.0
IL_0017: ldc.i4.s 123
IL_0019: stfld int32 EnumReflection.DerivedClass::age
IL_001e: ldarg.0
IL_001f: call instance void EnumReflection.BaseClass::.ctor()
IL_0024: nop
IL_0025: ret
} // end of method DerivedClass::.ctor
我知道这些代码是做什么的,因为我产生了它们:-)然而,我想了解更多关于相应的IL代码。
这些示例包含像这样的IL代码,您能用问号来解释命令吗?还有,这些命令代表什么?这样我们就可以很容易地记住它们。
<代码>H121ldstr?<代码>H222<代码>H123stfld?<代码>H224<代码>H125ldc.i4.s?<代码>H226<代码>H127.ctor-构造函数<代码>H228<代码>F229
理解IL很重要,因为它揭示了特定编译器如何在特定情况下生成代码和执行操作。
然而,我找不到一个很好的文档,里面也包含了关于IL的例子。CLR with C# 3.0是一本很好的书,但是它最终不是一本IL书,所以它没有解释关于IL的一切。
编辑:
我找到了规范,他们告诉我:,感谢@。
stfld-
https://stackoverflow.com/questions/10260272
复制相似问题