HelloWorld.cs //HelloWorld.cs by Cornfield,2001 //csc HelloWorld.cs using System; class HelloWorld { public static void Main() { Console.WriteLine("Hello World !"); } }
需要指出的是,我们一般使用C#编写生成一个HelloWorld的exe文件,其实,内部存放的并不是机器可以解读的机器码,不要被后缀名exe欺骗了。
// Microsoft (R) .NET Framework IL Disassembler. Version 1.1.4322.573 // Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 1:0:5000:0 } .assembly Class2 { // --- 下列自定义属性会自动添加,不要取消注释 ------- // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool, // bool) = ( 01 00 00 01 00 00 ) .hash algorithm 0x00008004 .ver 0:0:0:0 } .module Class2.exe // MVID: {A9D4A2DC-A401-4F5F-B16F-B3D40F584E59} .imagebase 0x00400000 .subsystem 0x00000003 .file alignment 512 .corflags 0x00000001 // Image base: 0x070c0000 // // ============== CLASS STRUCTURE DECLARATION ================== // .class public auto ansi beforefieldinit Test extends [mscorlib]System.Object { } // end of class Test // ============================================================= // =============== GLOBAL FIELDS AND METHODS =================== // ============================================================= // =============== CLASS MEMBERS DECLARATION =================== // note that class flags, 'extends' and 'implements' clauses // are provided here for information only .class public auto ansi beforefieldinit Test extends [mscorlib]System.Object { .method private hidebysig static void Main() cil managed { .entrypoint // 代码大小 72 (0x48) .maxstack 4 .locals init (int32[] V_0, int32 V_1, int32 V_2) IL_0000: ldc.i4.5 IL_0001: newarr [mscorlib]System.Int32 IL_0006: stloc.0 IL_0007: ldc.i4.0 IL_0008: stloc.1 IL_0009: br.s IL_0015 IL_000b: ldloc.0 IL_000c: ldloc.1 IL_000d: ldloc.1 IL_000e: ldloc.1 IL_000f: mul IL_0010: stelem.i4 IL_0011: ldloc.1 IL_0012: ldc.i4.1 IL_0013: add IL_0014: stloc.1 IL_0015: ldloc.1 IL_0016: ldloc.0 IL_0017: ldlen IL_0018: conv.i4 IL_0019: blt.s IL_000b IL_001b: ldc.i4.0 IL_001c: stloc.2 IL_001d: br.s IL_003b IL_001f: ldstr "arr[{0}]={1}" IL_0024: ldloc.2 IL_0025: box [mscorlib]System.Int32 IL_002a: ldloc.0 IL_002b: ldloc.2 IL_002c: ldelem.i4 IL_002d: box [mscorlib]System.Int32 IL_0032: call void [mscorlib]System.Console::WriteLine(string, object, object) IL_0037: ldloc.2 IL_0038: ldc.i4.1 IL_0039: add IL_003a: stloc.2 IL_003b: ldloc.2 IL_003c: ldloc.0 IL_003d: ldlen IL_003e: conv.i4 IL_003f: blt.s IL_001f IL_0041: call int32 [mscorlib]System.Console::Read() IL_0046: pop IL_0047: ret } // end of method Test::Main .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { // 代码大小 7 (0x7) .maxstack 1 IL_0000: ldarg.0 IL_0001: call instance void [mscorlib]System.Object::.ctor() IL_0006: ret } // end of method Test::.ctor } // end of class Test // ============================================================= //*********** 反汇编完成 *********************** // WARNING: Created Win32 resource file Class2.res