Hello, MSIL World!
Posted on 12月 31st, 2011 by cx20
MSIL
MSIL は .NET Framework で使用されている中間言語(Intermediate Language)である。
ソースコード
.assembly extern mscorlib {}
.assembly hello {}
.method static void Main() cil managed {
.entrypoint
ldstr "Hello, MSIL World!"
call void [mscorlib]System.Console::WriteLine(string)
ret
} |
.assembly extern mscorlib {}
.assembly hello {}
.method static void Main() cil managed {
.entrypoint
ldstr "Hello, MSIL World!"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
上記コードは以下の C# のソースに対応する。
アセンブリファイル(.NET でコンパイルしたモジュール)を ildasm で逆アセンブル(ildasdm hello.exe /out:hello.il)することで MSIL のコードを得られる。
using System;
class Hello
{
static void Main( String[] args )
{
Console.WriteLine( "Hello, MSIL World!" );
}
} |
using System;
class Hello
{
static void Main( String[] args )
{
Console.WriteLine( "Hello, MSIL World!" );
}
}
コンパイル&実行方法(Mono)
$ ilasm hello.il
$ mono hello.exe
コンパイル&実行方法(.NET Framework)
C:¥> ilasm hello.il
C:¥> hello |
C:¥> ilasm hello.il
C:¥> hello
実行結果
Tags: IL, MSIL
Categories: .NET, assembler, MSIL