LoginSignup
1
0

More than 1 year has passed since last update.

ilasmでstack machine その15

Posted at

概要

ilasmでstack machineやってみた。
練習問題やってみた。

練習問題

湯婆婆を実装せよ。

サンプルコード

.assembly extern mscorlib {
}
.assembly yuba {
}
.method static void main() {
.entrypoint
.locals init (string[] str)
	newobj instance void [mscorlib]System.Random::.ctor()
	ldstr	 "契約書\r\n"
	call	void [mscorlib]System.Console::WriteLine(string)
	ldstr	"甲は油屋当主として、乙を油屋に雇用することを契約し、\r\n"
	call	void [mscorlib]System.Console::WriteLine(string)
	ldstr	"労働に伴う対価の支払いを右の通り、約定する。\r\n"
	call	void [mscorlib]System.Console::WriteLine(string)
	ldstr	"なお、一日の労働の対価は金百円とする。\r\n"
	call	void [mscorlib]System.Console::WriteLine(string)
	ldstr	"甲 油屋当主 湯婆婆\r\n"
	call	void [mscorlib]System.Console::WriteLine(string)
	ldstr	"乙\r\n"
	call	void [mscorlib]System.Console::WriteLine(string)
	ldstr	"契約書だよ。そこに名前を書きな。"
	call	void [mscorlib]System.Console::WriteLine(string)
	call	string [mscorlib]System.Console::ReadLine()
	dup
	dup
	dup
	dup
	stloc	str
	ldstr	"フン。"
	call	void [mscorlib]System.Console::Write(string)
	call	void [mscorlib]System.Console::Write(string)
	ldstr	"というのかい。贅沢な名だねぇ。"
	call	void [mscorlib]System.Console::WriteLine(string)
	ldc.i4	2
	callvirt instance int32 [mscorlib]System.Random::Next(int32)
	ldloc	str
	callvirt instance int32 [mscorlib]System.String::get_Length()
	rem
	ldc.i4	1
	callvirt instance string [mscorlib]System.String::Substring(int32, int32)
	dup
	dup
	dup
	ldstr	"今からお前の名前は"
	call	void [mscorlib]System.Console::Write(string)
	call	void [mscorlib]System.Console::Write(string)
	ldstr	"だ。いいかい、"
	call	void [mscorlib]System.Console::Write(string)
	call	void [mscorlib]System.Console::Write(string)
	ldstr	"だよ。分かったら返事をするんだ、"
	call	void [mscorlib]System.Console::Write(string)
	call	void [mscorlib]System.Console::Write(string)
	ldstr	"!!"
	call	void [mscorlib]System.Console::WriteLine(string)
	ret
}

実行結果

>iyuba
契約書

甲は油屋当主として、乙を油屋に雇用することを契約し、

労働に伴う対価の支払いを右の通り、約定する。

なお、一日の労働の対価は金百円とする。

甲 油屋当主 湯婆婆

乙

契約書だよ。そこに名前を書きな。
矢田亜希子
フン。矢田亜希子というのかい。贅沢な名だねぇ。
今からお前の名前は矢だ。いいかい、矢だよ。分かったら返事をするんだ、矢!!

>

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0