现在的位置: 首页 > 综合 > 正文

初识IL..

2012年06月27日 ⁄ 综合 ⁄ 共 1528字 ⁄ 字号 评论关闭
M A N I F E S T  // 附加信息列表
------------------------------------------------
.assembly extern mscorlib { }    // 加载外部核心库
.assembly HelloWorld            // 定义编译目标
{
    .hash algorithm        
// 默认SHA1算法
    .ver                // HelloWorld程序集的版本号
}
        
.module HelloWorld.exe    
// module为程序集指令,表明定义的模块的元数据
.subsystem 0x0003        // 连接系统类型,0x0003表示从控制台运行

H e l l o W o r l d
------------------------------------------------

.class public auto ansi beforefieldinit HelloWorld
       extends [mscorlib]System.Object
{
    .
class    // 表明是一个类
    auto    // 表明程序加载时,内存的布局是由CLR决定的
    ansi    // 没有被托管和托管代码间实现无缝转换,没有被托管的代码指的是以前的C、C++这些没有运行在CLR库之上的代码
    beforefieldinit    // 用于标记运行库可以在 任何时候 执行类型 构造函数方法
}

.c t o r 构 造 函 数 // 调用基类的构造函数
------------------------------------------------

.method public hidebysig specialname rtspecialname 
        instance 
void  .ctor() cil managed    // cil managed说明方法体中为IL代码,指示编译器编译 为托管代码
{
  
// Code size       7 (0x7)
  .maxstack  8    // 表示构造函数.ctor()期间的评估堆栈
  
// IL_0000之前的部分一般为变量声明、初始化
  IL_0000:  ldarg.0        // 表示装载第一个成员参数
  IL_0001:  call       instance void [mscorlib]System.Object::.ctor() // 此处的Call 用于调用父类的.ctor()构造函数
  IL_0006:  ret            // 执行完毕,返回
}

M a i n 方法
------------------------------------------------

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint    
// 函数入口点
  
// Code size       13 (0xd)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldstr      
"Hello World !"    // 装载String对象
  IL_0006:  call       void [mscorlib]System.Console::WriteLine(string// 调用静态方法
  IL_000b:  nop
  IL_000c:  ret
}

抱歉!评论已关闭.