1
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?

ilasmAdvent Calendar 2024

Day 16

ilasmでstack machine その34

Last updated at Posted at 2024-11-06

概要

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

練習問題

ilasmで数9を4個つかって1から15までの数を表す式を実装せよ。

サンプルコード


.assembly extern mscorlib {}
.assembly d94 {}
.method static void main() {
.entrypoint
d1:
	ldc.i4	9
	ldc.i4	9
	sub
	ldc.i4	9
	ldc.i4	9
	div
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d2:
	ldc.i4	9
	ldc.i4	9
	div
	ldc.i4	9
	ldc.i4	9
	div
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d3:
	ldc.i4	9
	ldc.i4	9
	add
	ldc.i4	9
	add
	ldc.i4	9
	div
	call	void [mscorlib] System.Console::WriteLine(int32)
d4:
	ldc.i4	9
	ldc.i4	9
	add
	ldc.i4	9
	div
	ldc.i4	9
	pop 
	dup
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d5:
	ldc.i4	9
	ldc.i4	9
	ldc.i4	9
	add
	ldc.i4	9
	div
	dup
	add
	sub
	call	void [mscorlib] System.Console::WriteLine(int32)
d6:
	ldc.i4	9
	dup
	ldc.i4	9
	add
	ldc.i4	9
	add
	ldc.i4	9
	div
	sub
	call	void [mscorlib] System.Console::WriteLine(int32)
d7:
	ldc.i4	9
	ldc.i4	9
	ldc.i4	9
	add
	ldc.i4	9
	div
	sub
	call	void [mscorlib] System.Console::WriteLine(int32)
d8:
	ldc.i4	9
	ldc.i4	9
	ldc.i4	9
	div
	sub
	ldc.i4	9
	pop
	call	void [mscorlib] System.Console::WriteLine(int32)
d9:
	ldc.i4	9
	ldc.i4	9
	sub
	ldc.i4	9
	mul
	ldc.i4	9
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d10:
	ldc.i4	9
	ldc.i4	9
	div
	ldc.i4	9
	add
	ldc.i4	9
	pop
	call	void [mscorlib] System.Console::WriteLine(int32)
d11:
	ldc.i4	9
	ldc.i4	9
	ldc.i4	9
	add
	ldc.i4	9
	div
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d12:
	ldc.i4	9
	dup
	ldc.i4	9
	ldc.i4	9
	add
	add
	ldc.i4	9
	div
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d13:
	ldc.i4	9
	ldc.i4	9
	ldc.i4	9
	add
	ldc.i4	9
	div
	dup
	add
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d14:
	ldc.i4	9
	dup
	ldc.i4	9
	ldc.i4	9
	add
	ldc.i4	9
	div
	dup
	add
	sub
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
d15:
	ldc.i4	9
	dup
	dup
	ldc.i4	9
	add
	ldc.i4	9
	add
	ldc.i4	9
	div
	sub
	add
	call	void [mscorlib] System.Console::WriteLine(int32)
	ret
}


実行結果

>d94
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

以上

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?