本文介绍了如何学习IL在CLR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这些IL codeS我看多了,我想了解如何跨preT他们正确。

Since these IL codes what I see more, I like to learn how to interpret them correctly.

我找不到像C#编译器或任何其他的,所以我想我可以pretty的多拿剩下的工作后,我学这个常见的一个文档:

I couldn't find a documentation like C# Compiler or any other so I think I can pretty much take care of the rest after I learn this common ones:

下面是一些示例IL codeS含有什么,我需要知道的:

Below are some sample IL codes containing what I need to know :

示例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

我知道这些codeS这样做,因为我公司生产他们:-)不过,我想更多地了解相应的IL code。

I know what these codes do since I produced them :-) however I'd like to learn more about corresponding IL code.

这些样品中含有IL codeS一样,,并请你解释一下命令与问号?并且还做那些命令代表什么?因此,我们可以很容易地记住它们。

These samples contain IL codes like, and could you please explain command with question marks? and also what do those command stand for? So we can memorize them easily.

  • NOP(调试 - 无操作)
  • newobj(现在看来,这是建立在堆中新对象)
  • stloc.0?
  • ldloc.0?
  • RET?
  • ldarg.0?
  • ldstr?
  • stfld?
  • ldc.i4.s?
  • 在.ctor - 构造
  • nop (for debugging - no operation)
  • newobj (it seems it is creating new object in heap)
  • stloc.0 ?
  • ldloc.0 ?
  • ret ?
  • ldarg.0 ?
  • ldstr ?
  • stfld ?
  • ldc.i4.s ?
  • .ctor - constructor

了解IL是重要的,因为它暴露了编译器如何产生特别codeS和行为在特定情况下。

Understanding IL is important as it exposes how particular compiler produces codes and act in specific cases.

不过,我找不到它包含的例子还有约IL一个不错的文档。 CLR与C#3.0是一本好书,但最终它是不是一个IL书,因此并不能说明一切,IL。

However, I couldn't find a nice docs which contain examples as well about IL. CLR with C# 3.0 is a good book however eventually it isn't a IL book so it doesn't explain everything about IL.

编辑:

我发现的规格,他们告诉这些:由于@usr

  • NOP(调试 - 无操作)
  • newobj - 创建一个新的对象
  • stloc.0 - 从堆栈弹出值局部变量
  • ldloc.0? - 负载局部变量压入堆栈
  • RET - 从方法返回
  • ldarg.0 - 加载参数0到堆栈中。
  • ldstr - 加载一个字符串
  • stfld - 存储到一个对象的字段
  • ldc.i4.s - 按下NUM压入堆栈作为INT32,缩写形式。
  • 在.ctor - 构造
  • nop (for debugging - no operation)
  • newobj - create a new object
  • stloc.0 - pop value from stack to local variable
  • ldloc.0 ? - load local variable onto the stack
  • ret - return from method
  • ldarg.0 - Load argument 0 onto the stack.
  • ldstr - load a literal string
  • stfld - store into a field of an object
  • ldc.i4.s - Push num onto the stack as int32 , short form.
  • .ctor - constructor

推荐答案

微软标准化CLR和公布这些标准。三分区包含了大量有关IL / CIL的信息,是适合学习。这是一个很好的文件。

Microsoft standardized the CLR and published those standards. Partition III contains a wealth of information about IL/CIL and is suitable for learning. It is an excellent document.

您还可以了解IL以身作则。编译在C#中一些简单的方法,并期待在IL中的反射器(它有一个IL-模式)。

You can also learn IL by example. Compile a few simple methods in C# and look at the IL in reflector (it has an IL-mode).

这篇关于如何学习IL在CLR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 01:01