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?

8章 バーチャルマシン#2:プログラム制御

Posted at

はじめに

これは、「コンピュータシステムの理論と実装」(以下「Nand2Tetris」という)の第7章 バーチャルマシン#2プログラム制御のプロジェクトに対するレポートである。

プロジェクトに対するレポート

目標

  • 「プログラミング風呂ー」と「関数呼び出し」のコマンドに対応した機能を追加する

材料

  • Nand2Tetrisで定義しているアセンブラAPI仕様
  • Nand2Tetrisで定義しているVM仕様(第2部)
  • Ruby
  • アセンブラ
  • CPUエミュレータ
  • ハードウェアエミュレータ

実装

Parseモジュール

6つのコマンドをパースするコードを追加するとある。

  • C_LABEL
  • C_GOTO
  • C_IF
  • C_FUNCTION
  • C_RETURN
  • C_CALL
    7章ですでに実装済みである。

CodeWriterモジュール

  • writeInit
  • writeLabel
  • writeGoto
  • writeIf
  • writeCall
  • writeReturn
  • writeFunction

使用の中に具体的にどのようにPUSHするかPOPするか記載指定あるのそれを中述に実装すれば良い。

テスト

  • BasicLoop
  • Fibonatti
  • SimpleFunction
  • FibonattiElement
  • StaticTest

4年前に実装していた時は、fibonattiのあたりから動作がおかしくデバッグする気にもなれず少し挫折していたが、リファクタリングすることで、実際に動作させたいコマンドを確認しながらデバッグを行い最終的に全てのテストをクリアすることができた。

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?