Fix command symbols
This commit is contained in:
parent
4e49913808
commit
91dd0bb102
24
README.md
24
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:
|
Final hack instruction set count in brackets. Calculated by running:
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
php file.vm > file.asm
|
php file.vm > file.asm
|
||||||
ruby assembler.rb file.vm > file.hack
|
ruby assembler.rb file.vm > file.hack
|
||||||
|
@ -103,11 +102,24 @@ wc -l file.hack
|
||||||
|
|
||||||
### Arithmetic Commands
|
### Arithmetic Commands
|
||||||
|
|
||||||
- [x] SimpleAdd.vm (21)
|
- [x] `SimpleAdd.vm` (21)
|
||||||
- [x] StackTest.vm (334)
|
- [x] `StackTest.vm` (334)
|
||||||
|
|
||||||
### Memory Access Commands
|
### Memory Access Commands
|
||||||
|
|
||||||
- [x] BasicTest.vm (228)
|
- [x] `BasicTest.vm` (228)
|
||||||
- [x] PointerTest.vm (127)
|
- [x] `PointerTest.vm` (127)
|
||||||
- [ ] StackTest.vm
|
- [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`
|
||||||
|
|
|
@ -29,7 +29,7 @@ class CodeWriter {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeArithmetic(String $command ) {
|
function writeArithmetic(String $command) {
|
||||||
$stackDecrease=true;
|
$stackDecrease=true;
|
||||||
// Read top of stack to D
|
// Read top of stack to D
|
||||||
$this->write([
|
$this->write([
|
||||||
|
|
|
@ -3,16 +3,18 @@
|
||||||
namespace captn3m0\NandToTetris;
|
namespace captn3m0\NandToTetris;
|
||||||
|
|
||||||
class CommandType {
|
class CommandType {
|
||||||
const CALL = 0;
|
|
||||||
const PUSH = 1;
|
const PUSH = 1;
|
||||||
const POP = 2;
|
const POP = 2;
|
||||||
|
// Program Flow Commands
|
||||||
const LABEL= 3;
|
const LABEL= 3;
|
||||||
const GOTO= 4;
|
const GOTO= 4;
|
||||||
const IF= 5;
|
const IF= 5;
|
||||||
|
// Function Calling Commands
|
||||||
const FUNC= 6;
|
const FUNC= 6;
|
||||||
const RETURN= 7;
|
const RETURN= 7;
|
||||||
const ARITHMETIC= 8;
|
const CALL = 0;
|
||||||
|
|
||||||
|
const ARITHMETIC= 8;
|
||||||
const ARITHMETIC_COMMANDS = ['add', 'sub', 'neg', 'eq', 'gt', 'lt', 'and', 'or', 'not'];
|
const ARITHMETIC_COMMANDS = ['add', 'sub', 'neg', 'eq', 'gt', 'lt', 'and', 'or', 'not'];
|
||||||
|
|
||||||
public static function fromName(String $name) {
|
public static function fromName(String $name) {
|
||||||
|
@ -25,8 +27,8 @@ class CommandType {
|
||||||
"pop",
|
"pop",
|
||||||
"label",
|
"label",
|
||||||
"goto",
|
"goto",
|
||||||
"if",
|
"if-goto",
|
||||||
"func",
|
"function",
|
||||||
"return"
|
"return"
|
||||||
];
|
];
|
||||||
return array_search($name, $map);
|
return array_search($name, $map);
|
||||||
|
|
|
@ -58,7 +58,6 @@ class VMTranslator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(isset($argv[1])) {
|
if(isset($argv[1])) {
|
||||||
$vmt = new VMTranslator($argv[1]);
|
$vmt = new VMTranslator($argv[1]);
|
||||||
$vmt->translate();
|
$vmt->translate();
|
||||||
|
|
Loading…
Reference in New Issue