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

stack machineを愛でる。 その6

Posted at

概要

stack machineが、好きだ。
練習問題、やってみた。

練習問題

1から70までを、表示せよ。

考え方

メモリーアクセスは、無いので、変数を使う。set,getを使う。

  • set スタックの二番目を変数として、一番目の値をセット、1個減る。
  • get スタックの一番目を変数として、その値をセット

変数xは、表示用。
変数iは、カウント用。
if 使ってループする。
loopとskipは、ラベル。

サンプルコード

  push  "x"
  push  ""
  set 
  push  "i"
  push  "0"
  set
loop  push  "i"
  push  "i"
  get
  ++
  set
  get
  push  "x"
  push  "x"
  get
  push  "i"
  get
  add
  push  " "
  add
  set
  push  "i"
  get
  push  "70"
  >
  !
  if  skip
  jp  loop
skip  end

成果物

以上。

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?