diff --git a/README.md b/README.md index 2a904e5..1fd2745 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,6 @@ Counting number of instructions by `wc -l $file.hack` Final hack instruction set count in brackets. Calculated by running: - ``` php file.vm > file.asm ruby assembler.rb file.vm > file.hack @@ -103,11 +102,24 @@ wc -l file.hack ### Arithmetic Commands -- [x] SimpleAdd.vm (21) -- [x] StackTest.vm (334) +- [x] `SimpleAdd.vm` (21) +- [x] `StackTest.vm` (334) ### Memory Access Commands -- [x] BasicTest.vm (228) -- [x] PointerTest.vm (127) -- [ ] StackTest.vm +- [x] `BasicTest.vm` (228) +- [x] `PointerTest.vm` (127) +- [x] `StackTest.vm` (73) + +## [Project 7: Virtual Machine II - Program Control](https://www.nand2tetris.org/project07) + +### Program Flow Commands + +- [ ] `BasicLoop.vm` +- [ ] `Fibonacci.vm` + +## Function Calling Commands + +- [ ] `SimpleFunction.vm` +- [ ] `FibonacciElement.vm` +- [ ] `StaticsTest.vm` diff --git a/vm/CodeWriter.php b/vm/CodeWriter.php index 0558947..bf5418d 100644 --- a/vm/CodeWriter.php +++ b/vm/CodeWriter.php @@ -29,7 +29,7 @@ class CodeWriter { ]); } - function writeArithmetic(String $command ) { + function writeArithmetic(String $command) { $stackDecrease=true; // Read top of stack to D $this->write([ diff --git a/vm/CommandType.php b/vm/CommandType.php index 1a19655..5e6178c 100644 --- a/vm/CommandType.php +++ b/vm/CommandType.php @@ -3,16 +3,18 @@ namespace captn3m0\NandToTetris; class CommandType { - const CALL = 0; const PUSH = 1; const POP = 2; + // Program Flow Commands const LABEL= 3; const GOTO= 4; const IF= 5; + // Function Calling Commands const FUNC= 6; const RETURN= 7; - const ARITHMETIC= 8; + const CALL = 0; + const ARITHMETIC= 8; const ARITHMETIC_COMMANDS = ['add', 'sub', 'neg', 'eq', 'gt', 'lt', 'and', 'or', 'not']; public static function fromName(String $name) { @@ -25,8 +27,8 @@ class CommandType { "pop", "label", "goto", - "if", - "func", + "if-goto", + "function", "return" ]; return array_search($name, $map); diff --git a/vm/VMTranslator.php b/vm/VMTranslator.php index eea9d51..6b4dc61 100644 --- a/vm/VMTranslator.php +++ b/vm/VMTranslator.php @@ -58,7 +58,6 @@ class VMTranslator { } } - if(isset($argv[1])) { $vmt = new VMTranslator($argv[1]); $vmt->translate();