ILをやっているとまずは関数を見つける事をしなければいけないことに気付くと思います。そんなときは、VB.NetやC#を逆アセ、またはmsdnとにらめっこです。どなたか、ILのための開発環境知りませんか?
そろそろこれをやらないと、つらいでしょう。というわけでソースコード。
.assembly extern mscorlib{}
.assembly input_test{}
.method public static void main() cil managed
{
.entrypoint
.maxstack 1
call string [mscorlib]System.Console::ReadLine()
call void [mscorlib]System.Console::WriteLine(string)
ret
}山彦みたいなものですね。ひたすら繰り返します。
まあ、数字を扱えないとつらいんですよ。
.assembly extern mscorlib{}
.assembly input_test{}
.method public static void main() cil managed
{
.entrypoint
.maxstack 1
call string [mscorlib]System.Console::ReadLine()
call int32 [mscorlib]System.Convert::ToInt32(string)
call void [mscorlib]System.Console::WriteLine(int32)
ret
}
変な値や、文字を入れるともれなく例外を出してくれます。ちゃんと例外キャッチした方が良さそうですね。
.assembly extern mscorlib{}
.assembly input_test{}
.method public static void main() cil managed
{
.entrypoint
.maxstack 1
.locals(string str)
call string [mscorlib]System.Console::ReadLine()
stloc.0
.try{
ldloc.0
call int32 [mscorlib]System.Convert::ToInt32(string)
call void [mscorlib]System.Console::WriteLine(int32)
leave fin
}catch[mscorlib]System.Object
{
pop
ldstr "適切な範囲の数字をお願いいたします。"
call void [mscorlib]System.Console::WriteLine(string)
leave fin
}
fin:
ret
}
例外についてはまた後でやりましょう。一応上のでは例外キャッチしています。