概要
ilasmでstack machineやってみた。
練習問題やってみた。
練習問題
readlineを使え。
サンプルコード
.assembly extern mscorlib {
.ver 4:0:0:0
.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
}
.assembly 'Program' {
.custom instance void class [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::'.ctor'(int32) = (01 00 08 00 00 00 00 00)
.custom instance void class [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::'.ctor'() = (01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01)
.custom instance void class [mscorlib]System.Diagnostics.DebuggableAttribute::'.ctor'(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (01 00 07 01 00 00 00 00)
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.namespace SBRL.Demo.Disassembly {
.class private auto ansi beforefieldinit Program extends [mscorlib]System.Object {
.method public static hidebysig default void Main (string[] args) cil managed {
.entrypoint
.maxstack 5
.locals init (int32 V_0, int32 V_1)
call string class [mscorlib]System.Console::ReadLine()
call int32 int32::Parse(string)
stloc.0
ldc.i4.s 0x0a
stloc.1
ldstr "{0} + {1} = {2}"
ldloc.0
box [mscorlib]System.Int32
ldloc.1
box [mscorlib]System.Int32
ldloc.0
ldloc.1
add
box [mscorlib]System.Int32
call void class [mscorlib]System.Console::WriteLine(string, object, object, object)
ret
}
.method public hidebysig specialname rtspecialname instance default void '.ctor' () cil managed {
.maxstack 8
ldarg.0
call instance void object::'.ctor'()
ret
}
}
}
実行結果
>pr0
12
12 + 10 = 22
以上。