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 5 years have passed since last update.

ilasmでstack machine その2

Last updated at Posted at 2019-12-24

概要

ilasmでstack machineやってみた。
俺言語、案を考えてみた。

俺言語ニーモニック

ニーモニック 意味 stackの状態
% stack-1,stackの剰余を求める。 1個減る
+ stack-1,stackの加算を求める。 1個減る
/ stack-1,stackの除算を求める。 1個減る
* stack-1,stackの乗算を求める。 1個減る
- stack-1,stackの減算を求める。 1個減る
pushi 100 stackに整数100を積む。 1個増える
push "ok" stackに、文字列okを積む。 1個増える
set i 変数iにstackを入れる。 1個減る
get i stackに、変数iの値を入れる。 1個増える
call printi stackを数値で印字する。 1個減る
call prints stackを文字列で印字する。 1個減る
if tugi stack-1,stackが真ならtugiへ飛ぶ。 1個減る
if< tugi stack-1,stackが大ならtugiへ飛ぶ。 1個減る
jp tugi 無条件でtugiへ飛ぶ。 変化無し

サンプルコード

	pushi 	1
	set 	i
loop:
	get 	i
	pushi 	100
	if< 	bye
	get 	i
	pushi 	15
	%
	if		fizzbuzz
	get 	i
	push 	5
	%
	if		buzz
	get 	i
	push 	3
	%
	if 		fizz
	get 	i
	call 	printi
	jp 		tugi

fizzbuzz:
	push 	"fizzbuzz"
	jp 		print
buzz:
	push 	"buzz"
	jp 		print
fizz:
	push 	"fizz"

print:
	call 	prints

tugi:
	get 	i
	pushi 	1
	+
	set 	i
	jp 		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?