Monday, January 30, 2006

MSIL example

.assembly extern mscorlib {
}

.assembly FirstApp {
.hash algorithm 0x00008004
.ver 0:0:1:0
}

.module FirstApp.exe

.class public auto ansi beforefieldinit sealed MainApp extends

[mscorlib]System.Object {
.method public hidebysig static void Run(string[] args) cil managed {
.entrypoint
.maxstack 2
.locals init ([0] int32 counter, string hello)
ldstr "Hello World"
stloc.1
Start:
ldloc.0
ldc.i4.s 5
bge.s Ret
ldloc.1
call void [mscorlib]System.Console::WriteLine(string)
ldloc.0
ldc.i4.1
add
stloc.0
br.s Start
Ret:
call string [mscorlib]System.Console::ReadLine()
pop
ret
}
}
Save it as "FirstApp.il" and from the command line
compile it with "ilasm FirstApp.il".

No comments:

Post a Comment