概要
ilasmでstack machineやってみた。
練習問題やってみた。
練習問題
AtCoderを解け。
整数 a,b,cと、文字列 s が与えられます。 a+b+c の計算結果と、文字列 s を並べて表示しなさい。
サンプルコード
.assembly AtCoder {}
.method public static void Main() {
.entrypoint
.locals init ([0] int32 a, [1] string line, [2] string[] lines, [3] int32 b, [4] int32 c, [5] string s)
call string [System.Console]System.Console::ReadLine()
call int32 [System.Runtime]System.Int32::Parse(string)
stloc.0
call string [System.Console]System.Console::ReadLine()
stloc.1
ldloc.1
ldc.i4.1
newarr [System.Runtime]System.String
dup
ldc.i4.0
ldstr " "
stelem.ref
ldc.i4.0
callvirt instance string[] [System.Runtime]System.String::Split(string[], valuetype [System.Runtime]System.StringSplitOptions)
stloc.2
ldloc.2
ldc.i4.0
ldelem.ref
call int32 [System.Runtime]System.Int32::Parse(string)
stloc.3
ldloc.2
ldc.i4.1
ldelem.ref
call int32 [System.Runtime]System.Int32::Parse(string)
stloc.s 4
call string [System.Console]System.Console::ReadLine()
stloc.s 5
ldloc.0
ldloc.3
add
ldloc.s 4
add
stloc.0
ldloc.0
call void [System.Console]System.Console::Write(int32)
ldstr " "
call void [System.Console]System.Console::Write(string)
ldloc.s 5
call void [System.Console]System.Console::WriteLine(string)
ret
}
実行結果
>at0
1
2 3
test
6 test
以上。