0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ilasmでstack machine

0
Last updated at Posted at 2019-12-24

概要

ilasmでstack machineやってみた。
fizzbuzzに、コメント付けて見た。

サンプルコード

.assembly extern mscorlib {}
.assembly fizzbuzz {		//プログラム名
}
.method static void main() {
	.entrypoint
	.locals init(int32 i)	//変数の宣言
	ldc.i4 		1       //stackに1を積む
	stloc 		i       //変数iにstackの値を入れる。
loop:
	ldloc 		i		//stackに変数iの値を積む
	ldc.i4 		100
	bgt 		bye		//stack-1,stackを比べて小さいならbyeに飛ぶ。
	ldloc 		i
	ldc.i4 		15
	rem					//stack-1,stackの剰余を求める。
	brfalse 	fizzbuzz	//ゼロで無いならfizzbuzzに飛ぶ。
	ldloc 		i
	ldc.i4 		5
	rem
	brfalse 	buzz
	ldloc 		i
	ldc.i4 		3
	rem
	brfalse 	fizz
	ldloc 		i
	call 		void [mscorlib] System.Console::WriteLine(int32) //stackを印刷。
	br 			tugi	//tugiへ飛ぶ。

fizzbuzz:
	ldstr 		"fizzbuzz"   //stackに「fizzbuzz」を積む。
	br 			print
buzz:
	ldstr 		"buzz"
	br 			print
fizz:
	ldstr 		"fizz"

print:
	call 		void [mscorlib] System.Console::WriteLine(string)

tugi:
	ldloc 		i
	ldc.i4 		1
	add						//stack-1,stackの加算を求める。
	stloc 		i
	br 			loop

bye:
	ret
}


以上。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?