Anpassungen Path-Struktur
This commit is contained in:
6
original/projects/5/Add.hack
Normal file
6
original/projects/5/Add.hack
Normal file
@@ -0,0 +1,6 @@
|
||||
0000000000000010
|
||||
1110110000010000
|
||||
0000000000000011
|
||||
1110000010010000
|
||||
0000000000000000
|
||||
1110001100001000
|
||||
97
original/projects/5/CPU-external.cmp
Normal file
97
original/projects/5/CPU-external.cmp
Normal file
@@ -0,0 +1,97 @@
|
||||
|time | inM | instruction |reset| outM |writeM|address| pc |
|
||||
| 0+ | 0|0011000000111001| 0 |*******| 0 | 0 | 0|
|
||||
| 1 | 0|0011000000111001| 0 |*******| 0 | 12345 | 1|
|
||||
| 1+ | 0|1110110000010000| 0 |*******| 0 | 12345 | 1|
|
||||
| 2 | 0|1110110000010000| 0 |*******| 0 | 12345 | 2|
|
||||
| 2+ | 0|0101101110100000| 0 |*******| 0 | 12345 | 2|
|
||||
| 3 | 0|0101101110100000| 0 |*******| 0 | 23456 | 3|
|
||||
| 3+ | 0|1110000111110000| 0 |*******| 0 | 23456 | 3|
|
||||
| 4 | 0|1110000111110000| 0 |*******| 0 | 11111 | 4|
|
||||
| 4+ | 0|0000001111101011| 0 |*******| 0 | 11111 | 4|
|
||||
| 5 | 0|0000001111101011| 0 |*******| 0 | 1003 | 5|
|
||||
| 5+ | 0|1110001100001000| 0 | 11111| 1 | 1003 | 5|
|
||||
| 6 | 0|1110001100001000| 0 | 11111| 1 | 1003 | 6|
|
||||
| 6+ | 0|0000001111101100| 0 |*******| 0 | 1003 | 6|
|
||||
| 7 | 0|0000001111101100| 0 |*******| 0 | 1004 | 7|
|
||||
| 7+ | 0|1110001110011000| 0 | 11110| 1 | 1004 | 7|
|
||||
| 8 | 0|1110001110011000| 0 | 11109| 1 | 1004 | 8|
|
||||
| 8+ | 0|0000001111101000| 0 |*******| 0 | 1004 | 8|
|
||||
| 9 | 0|0000001111101000| 0 |*******| 0 | 1000 | 9|
|
||||
| 9+ | 11111|1111010011110000| 0 |*******| 0 | 1000 | 9|
|
||||
| 10 | 11111|1111010011110000| 0 |*******| 0 | 32767 | 10|
|
||||
| 10+ | 11111|0000000000001110| 0 |*******| 0 | 32767 | 10|
|
||||
| 11 | 11111|0000000000001110| 0 |*******| 0 | 14 | 11|
|
||||
| 11+ | 11111|1110001100000100| 0 |*******| 0 | 14 | 11|
|
||||
| 12 | 11111|1110001100000100| 0 |*******| 0 | 14 | 14|
|
||||
| 12+ | 11111|0000001111100111| 0 |*******| 0 | 14 | 14|
|
||||
| 13 | 11111|0000001111100111| 0 |*******| 0 | 999 | 15|
|
||||
| 13+ | 11111|1111110111100000| 0 |*******| 0 | 999 | 15|
|
||||
| 14 | 11111|1111110111100000| 0 |*******| 0 | 11112 | 16|
|
||||
| 14+ | 11111|1110001100101000| 0 | -1| 1 | 11112 | 16|
|
||||
| 15 | 11111|1110001100101000| 0 | -1| 1 | 32767 | 17|
|
||||
| 15+ | 11111|0000000000010101| 0 |*******| 0 | 32767 | 17|
|
||||
| 16 | 11111|0000000000010101| 0 |*******| 0 | 21 | 18|
|
||||
| 16+ | 11111|1110011111000010| 0 |*******| 0 | 21 | 18|
|
||||
| 17 | 11111|1110011111000010| 0 |*******| 0 | 21 | 21|
|
||||
| 17+ | 11111|0000000000000010| 0 |*******| 0 | 21 | 21|
|
||||
| 18 | 11111|0000000000000010| 0 |*******| 0 | 2 | 22|
|
||||
| 18+ | 11111|1110000010111000| 0 | 1| 1 | 2 | 22|
|
||||
| 19 | 11111|1110000010111000| 0 | 2| 1 | 1 | 23|
|
||||
| 19+ | 11111|1111110111001000| 0 | 11112| 1 | 1 | 23|
|
||||
| 20 | 11111|1111110111001000| 0 | 11112| 1 | 1 | 24|
|
||||
| 20+ | 11111|1111110010101000| 0 | 11110| 1 | 1 | 24|
|
||||
| 21 | 11111|1111110010101000| 0 | 11110| 1 | 11110 | 25|
|
||||
| 21+ | 11111|0000001111101000| 0 |*******| 0 | 11110 | 25|
|
||||
| 22 | 11111|0000001111101000| 0 |*******| 0 | 1000 | 26|
|
||||
| 22+ | 11111|1110111010010000| 0 |*******| 0 | 1000 | 26|
|
||||
| 23 | 11111|1110111010010000| 0 |*******| 0 | 1000 | 27|
|
||||
| 23+ | 11111|1110001100000001| 0 |*******| 0 | 1000 | 27|
|
||||
| 24 | 11111|1110001100000001| 0 |*******| 0 | 1000 | 28|
|
||||
| 24+ | 11111|1110001100000010| 0 |*******| 0 | 1000 | 28|
|
||||
| 25 | 11111|1110001100000010| 0 |*******| 0 | 1000 | 29|
|
||||
| 25+ | 11111|1110001100000011| 0 |*******| 0 | 1000 | 29|
|
||||
| 26 | 11111|1110001100000011| 0 |*******| 0 | 1000 | 30|
|
||||
| 26+ | 11111|1110001100000100| 0 |*******| 0 | 1000 | 30|
|
||||
| 27 | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1000|
|
||||
| 27+ | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1000|
|
||||
| 28 | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1000|
|
||||
| 28+ | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000|
|
||||
| 29 | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000|
|
||||
| 29+ | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000|
|
||||
| 30 | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000|
|
||||
| 30+ | 11111|1110101010010000| 0 |*******| 0 | 1000 | 1000|
|
||||
| 31 | 11111|1110101010010000| 0 |*******| 0 | 1000 | 1001|
|
||||
| 31+ | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1001|
|
||||
| 32 | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1002|
|
||||
| 32+ | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1002|
|
||||
| 33 | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1000|
|
||||
| 33+ | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1000|
|
||||
| 34 | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1000|
|
||||
| 34+ | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1000|
|
||||
| 35 | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1001|
|
||||
| 35+ | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1001|
|
||||
| 36 | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1002|
|
||||
| 36+ | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1002|
|
||||
| 37 | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000|
|
||||
| 37+ | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000|
|
||||
| 38 | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000|
|
||||
| 38+ | 11111|1110111111010000| 0 |*******| 0 | 1000 | 1000|
|
||||
| 39 | 11111|1110111111010000| 0 |*******| 0 | 1000 | 1001|
|
||||
| 39+ | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1001|
|
||||
| 40 | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1000|
|
||||
| 40+ | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1000|
|
||||
| 41 | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1001|
|
||||
| 41+ | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1001|
|
||||
| 42 | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1000|
|
||||
| 42+ | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1000|
|
||||
| 43 | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1001|
|
||||
| 43+ | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1001|
|
||||
| 44 | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1000|
|
||||
| 44+ | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000|
|
||||
| 45 | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1001|
|
||||
| 45+ | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1001|
|
||||
| 46 | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000|
|
||||
| 46+ | 11111|1110001100000111| 1 |*******| 0 | 1000 | 1000|
|
||||
| 47 | 11111|1110001100000111| 1 |*******| 0 | 1000 | 0|
|
||||
| 47+ | 11111|0111111111111111| 0 |*******| 0 | 1000 | 0|
|
||||
| 48 | 11111|0111111111111111| 0 |*******| 0 | 32767 | 1|
|
||||
161
original/projects/5/CPU-external.tst
Normal file
161
original/projects/5/CPU-external.tst
Normal file
@@ -0,0 +1,161 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/CPU-external.tst
|
||||
|
||||
// Tests the CPU by setting the instruction input to various binary values that
|
||||
// code Hack instructions, and outputting the values of the registers that are
|
||||
// supposed to be affected by the instructions.
|
||||
|
||||
load CPU.hdl,
|
||||
output-file CPU-external.out,
|
||||
compare-to CPU-external.cmp,
|
||||
// Tracks the time, the CPU inputs (inM, instruction, reset bit), and the CPU
|
||||
// outputs (outM, writeM bit, address, pc).
|
||||
output-list time%S1.3.1 inM%D0.6.0 instruction%B0.16.0 reset%B2.1.2 outM%D1.6.0 writeM%B3.1.2 addressM%D1.5.1 pc%D0.5.0;
|
||||
|
||||
set instruction %B0011000000111001, // @12345
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110110000010000, // D=A
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0101101110100000, // @23456
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110000111110000, // AD=A-D
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101011, // @1003
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100001000, // M=D
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101100, // @1004
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001110011000, // MD=D-1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101000, // @1000
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111010011110000, // AD=D-M
|
||||
set inM 11111,
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000000000001110, // @14
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;jlt
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111100111, // @999
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111110111100000, // A=M+1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100101000, // AM=D
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000000000010101, // @21
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110011111000010, // D+1;jeq
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000000000000010, // @2
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110000010111000, // AMD=D+A
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111110111001000, // M=M+1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111110010101000, // AM=M-1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101000, // @1000
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110111010010000, // D=-1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000001, // D;JGT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000010, // D;JEQ
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000011, // D;JGE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;JLT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000101, // D;JNE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000110, // D;JLE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000111, // D;JMP
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110101010010000, // D=0
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000001, // D;JGT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000010, // D;JEQ
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000011, // D;JGE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;JLT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000101, // D;JNE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000110, // D;JLE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000111, // D;JMP
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110111111010000, // D=1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000001, // D;JGT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000010, // D;JEQ
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000011, // D;JGE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;JLT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000101, // D;JNE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000110, // D;JLE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000111, // D;JMP
|
||||
tick, output, tock, output;
|
||||
|
||||
set reset 1;
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0111111111111111, // @32767
|
||||
set reset 0;
|
||||
tick, output, tock, output;
|
||||
97
original/projects/5/CPU.cmp
Normal file
97
original/projects/5/CPU.cmp
Normal file
@@ -0,0 +1,97 @@
|
||||
|time | inM | instruction |reset| outM |writeM|address| pc |DRegister|
|
||||
| 0+ | 0|0011000000111001| 0 |*******| 0 | 0 | 0| 0 |
|
||||
| 1 | 0|0011000000111001| 0 |*******| 0 | 12345 | 1| 0 |
|
||||
| 1+ | 0|1110110000010000| 0 |*******| 0 | 12345 | 1| 12345 |
|
||||
| 2 | 0|1110110000010000| 0 |*******| 0 | 12345 | 2| 12345 |
|
||||
| 2+ | 0|0101101110100000| 0 |*******| 0 | 12345 | 2| 12345 |
|
||||
| 3 | 0|0101101110100000| 0 |*******| 0 | 23456 | 3| 12345 |
|
||||
| 3+ | 0|1110000111110000| 0 |*******| 0 | 23456 | 3| 11111 |
|
||||
| 4 | 0|1110000111110000| 0 |*******| 0 | 11111 | 4| 11111 |
|
||||
| 4+ | 0|0000001111101011| 0 |*******| 0 | 11111 | 4| 11111 |
|
||||
| 5 | 0|0000001111101011| 0 |*******| 0 | 1003 | 5| 11111 |
|
||||
| 5+ | 0|1110001100001000| 0 | 11111| 1 | 1003 | 5| 11111 |
|
||||
| 6 | 0|1110001100001000| 0 | 11111| 1 | 1003 | 6| 11111 |
|
||||
| 6+ | 0|0000001111101100| 0 |*******| 0 | 1003 | 6| 11111 |
|
||||
| 7 | 0|0000001111101100| 0 |*******| 0 | 1004 | 7| 11111 |
|
||||
| 7+ | 0|1110001110011000| 0 | 11110| 1 | 1004 | 7| 11110 |
|
||||
| 8 | 0|1110001110011000| 0 | 11109| 1 | 1004 | 8| 11110 |
|
||||
| 8+ | 0|0000001111101000| 0 |*******| 0 | 1004 | 8| 11110 |
|
||||
| 9 | 0|0000001111101000| 0 |*******| 0 | 1000 | 9| 11110 |
|
||||
| 9+ | 11111|1111010011110000| 0 |*******| 0 | 1000 | 9| -1 |
|
||||
| 10 | 11111|1111010011110000| 0 |*******| 0 | 32767 | 10| -1 |
|
||||
| 10+ | 11111|0000000000001110| 0 |*******| 0 | 32767 | 10| -1 |
|
||||
| 11 | 11111|0000000000001110| 0 |*******| 0 | 14 | 11| -1 |
|
||||
| 11+ | 11111|1110001100000100| 0 |*******| 0 | 14 | 11| -1 |
|
||||
| 12 | 11111|1110001100000100| 0 |*******| 0 | 14 | 14| -1 |
|
||||
| 12+ | 11111|0000001111100111| 0 |*******| 0 | 14 | 14| -1 |
|
||||
| 13 | 11111|0000001111100111| 0 |*******| 0 | 999 | 15| -1 |
|
||||
| 13+ | 11111|1111110111100000| 0 |*******| 0 | 999 | 15| -1 |
|
||||
| 14 | 11111|1111110111100000| 0 |*******| 0 | 11112 | 16| -1 |
|
||||
| 14+ | 11111|1110001100101000| 0 | -1| 1 | 11112 | 16| -1 |
|
||||
| 15 | 11111|1110001100101000| 0 | -1| 1 | 32767 | 17| -1 |
|
||||
| 15+ | 11111|0000000000010101| 0 |*******| 0 | 32767 | 17| -1 |
|
||||
| 16 | 11111|0000000000010101| 0 |*******| 0 | 21 | 18| -1 |
|
||||
| 16+ | 11111|1110011111000010| 0 |*******| 0 | 21 | 18| -1 |
|
||||
| 17 | 11111|1110011111000010| 0 |*******| 0 | 21 | 21| -1 |
|
||||
| 17+ | 11111|0000000000000010| 0 |*******| 0 | 21 | 21| -1 |
|
||||
| 18 | 11111|0000000000000010| 0 |*******| 0 | 2 | 22| -1 |
|
||||
| 18+ | 11111|1110000010111000| 0 | 1| 1 | 2 | 22| 1 |
|
||||
| 19 | 11111|1110000010111000| 0 | 2| 1 | 1 | 23| 1 |
|
||||
| 19+ | 11111|1111110111001000| 0 | 11112| 1 | 1 | 23| 1 |
|
||||
| 20 | 11111|1111110111001000| 0 | 11112| 1 | 1 | 24| 1 |
|
||||
| 20+ | 11111|1111110010101000| 0 | 11110| 1 | 1 | 24| 1 |
|
||||
| 21 | 11111|1111110010101000| 0 | 11110| 1 | 11110 | 25| 1 |
|
||||
| 21+ | 11111|0000001111101000| 0 |*******| 0 | 11110 | 25| 1 |
|
||||
| 22 | 11111|0000001111101000| 0 |*******| 0 | 1000 | 26| 1 |
|
||||
| 22+ | 11111|1110111010010000| 0 |*******| 0 | 1000 | 26| -1 |
|
||||
| 23 | 11111|1110111010010000| 0 |*******| 0 | 1000 | 27| -1 |
|
||||
| 23+ | 11111|1110001100000001| 0 |*******| 0 | 1000 | 27| -1 |
|
||||
| 24 | 11111|1110001100000001| 0 |*******| 0 | 1000 | 28| -1 |
|
||||
| 24+ | 11111|1110001100000010| 0 |*******| 0 | 1000 | 28| -1 |
|
||||
| 25 | 11111|1110001100000010| 0 |*******| 0 | 1000 | 29| -1 |
|
||||
| 25+ | 11111|1110001100000011| 0 |*******| 0 | 1000 | 29| -1 |
|
||||
| 26 | 11111|1110001100000011| 0 |*******| 0 | 1000 | 30| -1 |
|
||||
| 26+ | 11111|1110001100000100| 0 |*******| 0 | 1000 | 30| -1 |
|
||||
| 27 | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1000| -1 |
|
||||
| 27+ | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1000| -1 |
|
||||
| 28 | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1000| -1 |
|
||||
| 28+ | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000| -1 |
|
||||
| 29 | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000| -1 |
|
||||
| 29+ | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000| -1 |
|
||||
| 30 | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000| -1 |
|
||||
| 30+ | 11111|1110101010010000| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 31 | 11111|1110101010010000| 0 |*******| 0 | 1000 | 1001| 0 |
|
||||
| 31+ | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1001| 0 |
|
||||
| 32 | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1002| 0 |
|
||||
| 32+ | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1002| 0 |
|
||||
| 33 | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 33+ | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 34 | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 34+ | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 35 | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1001| 0 |
|
||||
| 35+ | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1001| 0 |
|
||||
| 36 | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1002| 0 |
|
||||
| 36+ | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1002| 0 |
|
||||
| 37 | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 37+ | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 38 | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000| 0 |
|
||||
| 38+ | 11111|1110111111010000| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 39 | 11111|1110111111010000| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 39+ | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 40 | 11111|1110001100000001| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 40+ | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 41 | 11111|1110001100000010| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 41+ | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 42 | 11111|1110001100000011| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 42+ | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 43 | 11111|1110001100000100| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 43+ | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 44 | 11111|1110001100000101| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 44+ | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 45 | 11111|1110001100000110| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 45+ | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1001| 1 |
|
||||
| 46 | 11111|1110001100000111| 0 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 46+ | 11111|1110001100000111| 1 |*******| 0 | 1000 | 1000| 1 |
|
||||
| 47 | 11111|1110001100000111| 1 |*******| 0 | 1000 | 0| 1 |
|
||||
| 47+ | 11111|0111111111111111| 0 |*******| 0 | 1000 | 0| 1 |
|
||||
| 48 | 11111|0111111111111111| 0 |*******| 0 | 32767 | 1| 1 |
|
||||
36
original/projects/5/CPU.hdl
Normal file
36
original/projects/5/CPU.hdl
Normal file
@@ -0,0 +1,36 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/CPU.hdl
|
||||
/**
|
||||
* The Hack Central Processing unit (CPU).
|
||||
* Parses the binary code in the instruction input and executes it according to the
|
||||
* Hack machine language specification. In the case of a C-instruction, computes the
|
||||
* function specified by the instruction. If the instruction specifies to read a memory
|
||||
* value, the inM input is expected to contain this value. If the instruction specifies
|
||||
* to write a value to the memory, sets the outM output to this value, sets the addressM
|
||||
* output to the target address, and asserts the writeM output (when writeM = 0, any
|
||||
* value may appear in outM).
|
||||
* If the reset input is 0, computes the address of the next instruction and sets the
|
||||
* pc output to that value. If the reset input is 1, sets pc to 0.
|
||||
* Note: The outM and writeM outputs are combinational: they are affected by the
|
||||
* instruction's execution during the current cycle. The addressM and pc outputs are
|
||||
* clocked: although they are affected by the instruction's execution, they commit to
|
||||
* their new values only in the next cycle.
|
||||
*/
|
||||
CHIP CPU {
|
||||
|
||||
IN inM[16], // M value input (M = contents of RAM[A])
|
||||
instruction[16], // Instruction for execution
|
||||
reset; // Signals whether to re-start the current
|
||||
// program (reset==1) or continue executing
|
||||
// the current program (reset==0).
|
||||
|
||||
OUT outM[16], // M value output
|
||||
writeM, // Write to M?
|
||||
addressM[15], // Address in data memory (of M)
|
||||
pc[15]; // address of next instruction
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
}
|
||||
161
original/projects/5/CPU.tst
Normal file
161
original/projects/5/CPU.tst
Normal file
@@ -0,0 +1,161 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/CPU.tst
|
||||
|
||||
// Tests the CPU by setting the instruction input to various binary values that
|
||||
// code Hack instructions, and outputting the values of the registers that are
|
||||
// supposed to be affected by the instructions.
|
||||
|
||||
load CPU.hdl,
|
||||
output-file CPU.out,
|
||||
compare-to CPU.cmp,
|
||||
// Tracks the time, the CPU inputs (inM, instruction, reset bit), the CPU
|
||||
// outputs (outM, writeM bit, address, pc), and the value of the D-register.
|
||||
output-list time%S1.3.1 inM%D0.6.0 instruction%B0.16.0 reset%B2.1.2 outM%D1.6.0 writeM%B3.1.2 addressM%D1.5.1 pc%D0.5.0 DRegister[]%D1.7.1;
|
||||
|
||||
set instruction %B0011000000111001, // @12345
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110110000010000, // D=A
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0101101110100000, // @23456
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110000111110000, // AD=A-D
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101011, // @1003
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100001000, // M=D
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101100, // @1004
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001110011000, // MD=D-1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101000, // @1000
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111010011110000, // AD=D-M
|
||||
set inM 11111,
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000000000001110, // @14
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;jlt
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111100111, // @999
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111110111100000, // A=M+1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100101000, // AM=D
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000000000010101, // @21
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110011111000010, // D+1;jeq
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000000000000010, // @2
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110000010111000, // AMD=D+A
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111110111001000, // M=M+1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1111110010101000, // AM=M-1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0000001111101000, // @1000
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110111010010000, // D=-1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000001, // D;JGT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000010, // D;JEQ
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000011, // D;JGE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;JLT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000101, // D;JNE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000110, // D;JLE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000111, // D;JMP
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110101010010000, // D=0
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000001, // D;JGT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000010, // D;JEQ
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000011, // D;JGE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;JLT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000101, // D;JNE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000110, // D;JLE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000111, // D;JMP
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110111111010000, // D=1
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000001, // D;JGT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000010, // D;JEQ
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000011, // D;JGE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000100, // D;JLT
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000101, // D;JNE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000110, // D;JLE
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B1110001100000111, // D;JMP
|
||||
tick, output, tock, output;
|
||||
|
||||
set reset 1;
|
||||
tick, output, tock, output;
|
||||
|
||||
set instruction %B0111111111111111, // @32767
|
||||
set reset 0;
|
||||
tick, output, tock, output;
|
||||
22
original/projects/5/Computer.hdl
Normal file
22
original/projects/5/Computer.hdl
Normal file
@@ -0,0 +1,22 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/Computer.hdl
|
||||
/**
|
||||
* The Hack computer, consisting of CPU, ROM and RAM.
|
||||
* When reset = 0, the program stored in the ROM executes.
|
||||
* When reset = 1, the program's execution restarts.
|
||||
* Thus, to start running the currently loaded program,
|
||||
* set reset to 1, and then set it to 0.
|
||||
* From this point onwards, the user is at the mercy of the software.
|
||||
* Depending on the program's code, and whether the code is correct,
|
||||
* the screen may show some output, the user may be expected to enter
|
||||
* some input using the keyboard, or the program may do some procerssing.
|
||||
*/
|
||||
CHIP Computer {
|
||||
|
||||
IN reset;
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
}
|
||||
15
original/projects/5/ComputerAdd.cmp
Normal file
15
original/projects/5/ComputerAdd.cmp
Normal file
@@ -0,0 +1,15 @@
|
||||
|time |reset|ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]|
|
||||
| 0 | 0 | 0 | 0 | 0| 0 | 0 | 0 |
|
||||
| 1 | 0 | 2 | 0 | 1| 0 | 0 | 0 |
|
||||
| 2 | 0 | 2 | 2 | 2| 0 | 0 | 0 |
|
||||
| 3 | 0 | 3 | 2 | 3| 0 | 0 | 0 |
|
||||
| 4 | 0 | 3 | 5 | 4| 0 | 0 | 0 |
|
||||
| 5 | 0 | 0 | 5 | 5| 0 | 0 | 0 |
|
||||
| 6 | 0 | 0 | 5 | 6| 5 | 0 | 0 |
|
||||
| 7 | 1 | 0 | 5 | 0| 0 | 0 | 0 |
|
||||
| 8 | 0 | 2 | 5 | 1| 0 | 0 | 0 |
|
||||
| 9 | 0 | 2 | 2 | 2| 0 | 0 | 0 |
|
||||
| 10 | 0 | 3 | 2 | 3| 0 | 0 | 0 |
|
||||
| 11 | 0 | 3 | 5 | 4| 0 | 0 | 0 |
|
||||
| 12 | 0 | 0 | 5 | 5| 0 | 0 | 0 |
|
||||
| 13 | 0 | 0 | 5 | 6| 5 | 0 | 0 |
|
||||
35
original/projects/5/ComputerAdd.tst
Normal file
35
original/projects/5/ComputerAdd.tst
Normal file
@@ -0,0 +1,35 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/ComputerAdd.tst
|
||||
|
||||
// Tests the Computer chip by having it execute the program Add.hack.
|
||||
// The program adds up the constants 2 and 3 and writes the result in RAM[0].
|
||||
|
||||
load Computer.hdl,
|
||||
output-file ComputerAdd.out,
|
||||
compare-to ComputerAdd.cmp,
|
||||
// Tracks the values of the time, reset bit, A-register, D-register,
|
||||
// program counter, R0, R1, and R2.
|
||||
output-list time%S1.3.1 reset%B2.1.2 ARegister[0]%D1.7.1 DRegister[0]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
|
||||
|
||||
// Loads the binary program Add.hack into the computer's instruction memory
|
||||
ROM32K load Add.hack,
|
||||
output;
|
||||
|
||||
// First run (at the beginning PC=0)
|
||||
repeat 6 {
|
||||
tick, tock, output;
|
||||
}
|
||||
|
||||
// Resets the PC
|
||||
set reset 1,
|
||||
set RAM16K[0] 0,
|
||||
tick, tock, output;
|
||||
|
||||
// Second run, to check that the PC was reset correctly.
|
||||
set reset 0,
|
||||
|
||||
repeat 6 {
|
||||
tick, tock, output;
|
||||
}
|
||||
28
original/projects/5/ComputerMax.cmp
Normal file
28
original/projects/5/ComputerMax.cmp
Normal file
@@ -0,0 +1,28 @@
|
||||
|time |reset|ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]|
|
||||
| 0 | 0 | 0 | 0 | 0| 3 | 5 | 0 |
|
||||
| 1 | 0 | 0 | 0 | 1| 3 | 5 | 0 |
|
||||
| 2 | 0 | 0 | 3 | 2| 3 | 5 | 0 |
|
||||
| 3 | 0 | 1 | 3 | 3| 3 | 5 | 0 |
|
||||
| 4 | 0 | 1 | -2 | 4| 3 | 5 | 0 |
|
||||
| 5 | 0 | 10 | -2 | 5| 3 | 5 | 0 |
|
||||
| 6 | 0 | 10 | -2 | 6| 3 | 5 | 0 |
|
||||
| 7 | 0 | 1 | -2 | 7| 3 | 5 | 0 |
|
||||
| 8 | 0 | 1 | 5 | 8| 3 | 5 | 0 |
|
||||
| 9 | 0 | 12 | 5 | 9| 3 | 5 | 0 |
|
||||
| 10 | 0 | 12 | 5 | 12| 3 | 5 | 0 |
|
||||
| 11 | 0 | 2 | 5 | 13| 3 | 5 | 0 |
|
||||
| 12 | 0 | 2 | 5 | 14| 3 | 5 | 5 |
|
||||
| 13 | 0 | 14 | 5 | 15| 3 | 5 | 5 |
|
||||
| 14 | 0 | 14 | 5 | 14| 3 | 5 | 5 |
|
||||
| 15 | 1 | 14 | 5 | 0| 3 | 5 | 5 |
|
||||
| 15 | 0 | 14 | 5 | 0| 23456 | 12345 | 5 |
|
||||
| 16 | 0 | 0 | 5 | 1| 23456 | 12345 | 5 |
|
||||
| 17 | 0 | 0 | 23456 | 2| 23456 | 12345 | 5 |
|
||||
| 18 | 0 | 1 | 23456 | 3| 23456 | 12345 | 5 |
|
||||
| 19 | 0 | 1 | 11111 | 4| 23456 | 12345 | 5 |
|
||||
| 20 | 0 | 10 | 11111 | 5| 23456 | 12345 | 5 |
|
||||
| 21 | 0 | 10 | 11111 | 10| 23456 | 12345 | 5 |
|
||||
| 22 | 0 | 0 | 11111 | 11| 23456 | 12345 | 5 |
|
||||
| 23 | 0 | 0 | 23456 | 12| 23456 | 12345 | 5 |
|
||||
| 24 | 0 | 2 | 23456 | 13| 23456 | 12345 | 5 |
|
||||
| 25 | 0 | 2 | 23456 | 14| 23456 | 12345 | 23456 |
|
||||
41
original/projects/5/ComputerMax.tst
Normal file
41
original/projects/5/ComputerMax.tst
Normal file
@@ -0,0 +1,41 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/ComputerMax.tst
|
||||
|
||||
// Tests the Computer chip by having it execute the program Max.hack.
|
||||
// The program computes maximum(R0, R1) and writes the result in RAM[2].
|
||||
|
||||
load Computer.hdl,
|
||||
output-file ComputerMax.out,
|
||||
compare-to ComputerMax.cmp,
|
||||
// Tracks the values of the time, reset bit, A-register, D-register,
|
||||
// program counter, R0, R1, and R2.
|
||||
output-list time%S1.3.1 reset%B2.1.2 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
|
||||
|
||||
// Loads the binary program Add.hack into the computer's instruction memory
|
||||
ROM32K load Max.hack,
|
||||
|
||||
// first run: computes max(3,5)
|
||||
set RAM16K[0] 3,
|
||||
set RAM16K[1] 5,
|
||||
output;
|
||||
|
||||
repeat 14 {
|
||||
tick, tock, output;
|
||||
}
|
||||
|
||||
// resets the PC
|
||||
set reset 1,
|
||||
tick, tock, output;
|
||||
|
||||
// second run: computes max(23456,12345)
|
||||
set reset 0,
|
||||
set RAM16K[0] 23456,
|
||||
set RAM16K[1] 12345,
|
||||
output;
|
||||
|
||||
// The run on these inputs requires less cycles (different branching)
|
||||
repeat 10 {
|
||||
tick, tock, output;
|
||||
}
|
||||
65
original/projects/5/ComputerRect.cmp
Normal file
65
original/projects/5/ComputerRect.cmp
Normal file
@@ -0,0 +1,65 @@
|
||||
|time |ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]|
|
||||
| 0 | 0 | 0 | 0| 4 | 0 | 0 |
|
||||
| 1 | 0 | 0 | 1| 4 | 0 | 0 |
|
||||
| 2 | 0 | 4 | 2| 4 | 0 | 0 |
|
||||
| 3 | 23 | 4 | 3| 4 | 0 | 0 |
|
||||
| 4 | 23 | 4 | 4| 4 | 0 | 0 |
|
||||
| 5 | 16 | 4 | 5| 4 | 0 | 0 |
|
||||
| 6 | 16 | 4 | 6| 4 | 0 | 0 |
|
||||
| 7 | 16384 | 4 | 7| 4 | 0 | 0 |
|
||||
| 8 | 16384 | 16384 | 8| 4 | 0 | 0 |
|
||||
| 9 | 17 | 16384 | 9| 4 | 0 | 0 |
|
||||
| 10 | 17 | 16384 | 10| 4 | 0 | 0 |
|
||||
| 11 | 17 | 16384 | 11| 4 | 0 | 0 |
|
||||
| 12 | 16384 | 16384 | 12| 4 | 0 | 0 |
|
||||
| 13 | 16384 | 16384 | 13| 4 | 0 | 0 |
|
||||
| 14 | 17 | 16384 | 14| 4 | 0 | 0 |
|
||||
| 15 | 17 | 16384 | 15| 4 | 0 | 0 |
|
||||
| 16 | 32 | 16384 | 16| 4 | 0 | 0 |
|
||||
| 17 | 32 | 16416 | 17| 4 | 0 | 0 |
|
||||
| 18 | 17 | 16416 | 18| 4 | 0 | 0 |
|
||||
| 19 | 17 | 16416 | 19| 4 | 0 | 0 |
|
||||
| 20 | 16 | 16416 | 20| 4 | 0 | 0 |
|
||||
| 21 | 16 | 3 | 21| 4 | 0 | 0 |
|
||||
| 22 | 10 | 3 | 22| 4 | 0 | 0 |
|
||||
| 23 | 10 | 3 | 10| 4 | 0 | 0 |
|
||||
| 24 | 17 | 3 | 11| 4 | 0 | 0 |
|
||||
| 25 | 16416 | 3 | 12| 4 | 0 | 0 |
|
||||
| 26 | 16416 | 3 | 13| 4 | 0 | 0 |
|
||||
| 27 | 17 | 3 | 14| 4 | 0 | 0 |
|
||||
| 28 | 17 | 16416 | 15| 4 | 0 | 0 |
|
||||
| 29 | 32 | 16416 | 16| 4 | 0 | 0 |
|
||||
| 30 | 32 | 16448 | 17| 4 | 0 | 0 |
|
||||
| 31 | 17 | 16448 | 18| 4 | 0 | 0 |
|
||||
| 32 | 17 | 16448 | 19| 4 | 0 | 0 |
|
||||
| 33 | 16 | 16448 | 20| 4 | 0 | 0 |
|
||||
| 34 | 16 | 2 | 21| 4 | 0 | 0 |
|
||||
| 35 | 10 | 2 | 22| 4 | 0 | 0 |
|
||||
| 36 | 10 | 2 | 10| 4 | 0 | 0 |
|
||||
| 37 | 17 | 2 | 11| 4 | 0 | 0 |
|
||||
| 38 | 16448 | 2 | 12| 4 | 0 | 0 |
|
||||
| 39 | 16448 | 2 | 13| 4 | 0 | 0 |
|
||||
| 40 | 17 | 2 | 14| 4 | 0 | 0 |
|
||||
| 41 | 17 | 16448 | 15| 4 | 0 | 0 |
|
||||
| 42 | 32 | 16448 | 16| 4 | 0 | 0 |
|
||||
| 43 | 32 | 16480 | 17| 4 | 0 | 0 |
|
||||
| 44 | 17 | 16480 | 18| 4 | 0 | 0 |
|
||||
| 45 | 17 | 16480 | 19| 4 | 0 | 0 |
|
||||
| 46 | 16 | 16480 | 20| 4 | 0 | 0 |
|
||||
| 47 | 16 | 1 | 21| 4 | 0 | 0 |
|
||||
| 48 | 10 | 1 | 22| 4 | 0 | 0 |
|
||||
| 49 | 10 | 1 | 10| 4 | 0 | 0 |
|
||||
| 50 | 17 | 1 | 11| 4 | 0 | 0 |
|
||||
| 51 | 16480 | 1 | 12| 4 | 0 | 0 |
|
||||
| 52 | 16480 | 1 | 13| 4 | 0 | 0 |
|
||||
| 53 | 17 | 1 | 14| 4 | 0 | 0 |
|
||||
| 54 | 17 | 16480 | 15| 4 | 0 | 0 |
|
||||
| 55 | 32 | 16480 | 16| 4 | 0 | 0 |
|
||||
| 56 | 32 | 16512 | 17| 4 | 0 | 0 |
|
||||
| 57 | 17 | 16512 | 18| 4 | 0 | 0 |
|
||||
| 58 | 17 | 16512 | 19| 4 | 0 | 0 |
|
||||
| 59 | 16 | 16512 | 20| 4 | 0 | 0 |
|
||||
| 60 | 16 | 0 | 21| 4 | 0 | 0 |
|
||||
| 61 | 10 | 0 | 22| 4 | 0 | 0 |
|
||||
| 62 | 10 | 0 | 23| 4 | 0 | 0 |
|
||||
| 63 | 23 | 0 | 24| 4 | 0 | 0 |
|
||||
29
original/projects/5/ComputerRect.tst
Normal file
29
original/projects/5/ComputerRect.tst
Normal file
@@ -0,0 +1,29 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/ComputerRect.tst
|
||||
|
||||
// Tests the Computer chip by having it execute the program Rect.hack.
|
||||
// The program draws a rectangle of width 16 pixels and length RAM[0]
|
||||
// at the top left corner of the screen.
|
||||
|
||||
load Computer.hdl,
|
||||
output-file ComputerRect.out,
|
||||
compare-to ComputerRect.cmp,
|
||||
// Tracks the values of the time, A-register, D-register, program counter, R0, R1, and R2.
|
||||
output-list time%S1.3.1 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
|
||||
|
||||
// Loads the binary program Rect.hack into the computer's instruction memory
|
||||
ROM32K load Rect.hack,
|
||||
|
||||
echo "Before you run this script, select the 'Screen' option from the 'View' menu";
|
||||
|
||||
echo "A small rectangle should be drawn at the top left of the screen (the 'Screen' option of the 'View' menu should be selected.)";
|
||||
|
||||
// Draws a rectangle consisting of 4 rows (each 16 pixels wide)
|
||||
set RAM16K[0] 4,
|
||||
output;
|
||||
|
||||
repeat 63 {
|
||||
tick, tock, output;
|
||||
}
|
||||
16
original/projects/5/Max.hack
Normal file
16
original/projects/5/Max.hack
Normal file
@@ -0,0 +1,16 @@
|
||||
0000000000000000
|
||||
1111110000010000
|
||||
0000000000000001
|
||||
1111010011010000
|
||||
0000000000001010
|
||||
1110001100000001
|
||||
0000000000000001
|
||||
1111110000010000
|
||||
0000000000001100
|
||||
1110101010000111
|
||||
0000000000000000
|
||||
1111110000010000
|
||||
0000000000000010
|
||||
1110001100001000
|
||||
0000000000001110
|
||||
1110101010000111
|
||||
68
original/projects/5/Memory.cmp
Normal file
68
original/projects/5/Memory.cmp
Normal file
@@ -0,0 +1,68 @@
|
||||
| in |load | address | out |
|
||||
| 12345 | 1 | 010000000000000 | 0 |
|
||||
| 12345 | 1 | 010000000000000 | 12345 |
|
||||
| 12345 | 1 | 100000000000000 | 0 |
|
||||
| 12345 | 1 | 100000000000000 | 12345 |
|
||||
| -1 | 1 | 000000000000000 | 0 |
|
||||
| -1 | 1 | 000000000000000 | -1 |
|
||||
| 9999 | 0 | 000000000000000 | -1 |
|
||||
| 9999 | 0 | 000000000000000 | -1 |
|
||||
| 9999 | 0 | 010000000000000 | 12345 |
|
||||
| 9999 | 0 | 100000000000000 | 12345 |
|
||||
| 12345 | 1 | 000000000000000 | -1 |
|
||||
| 12345 | 1 | 000000000000000 | 12345 |
|
||||
| 12345 | 1 | 100000000000000 | 12345 |
|
||||
| 12345 | 1 | 100000000000000 | 12345 |
|
||||
| 2222 | 1 | 010000000000000 | 12345 |
|
||||
| 2222 | 1 | 010000000000000 | 2222 |
|
||||
| 9999 | 0 | 010000000000000 | 2222 |
|
||||
| 9999 | 0 | 010000000000000 | 2222 |
|
||||
| 9999 | 0 | 000000000000000 | 12345 |
|
||||
| 9999 | 0 | 100000000000000 | 12345 |
|
||||
| 9999 | 0 | 000000000000001 | 0 |
|
||||
| 9999 | 0 | 000000000000010 | 0 |
|
||||
| 9999 | 0 | 000000000000100 | 0 |
|
||||
| 9999 | 0 | 000000000001000 | 0 |
|
||||
| 9999 | 0 | 000000000010000 | 0 |
|
||||
| 9999 | 0 | 000000000100000 | 0 |
|
||||
| 9999 | 0 | 000000001000000 | 0 |
|
||||
| 9999 | 0 | 000000010000000 | 0 |
|
||||
| 9999 | 0 | 000000100000000 | 0 |
|
||||
| 9999 | 0 | 000001000000000 | 0 |
|
||||
| 9999 | 0 | 000010000000000 | 0 |
|
||||
| 9999 | 0 | 000100000000000 | 0 |
|
||||
| 9999 | 0 | 001000000000000 | 0 |
|
||||
| 9999 | 0 | 010000000000000 | 2222 |
|
||||
| 1234 | 1 | 001001000110100 | 0 |
|
||||
| 1234 | 1 | 001001000110100 | 1234 |
|
||||
| 1234 | 0 | 010001000110100 | 0 |
|
||||
| 1234 | 0 | 110001000110100 | 0 |
|
||||
| 2345 | 1 | 010001101000101 | 0 |
|
||||
| 2345 | 1 | 010001101000101 | 2345 |
|
||||
| 2345 | 0 | 000001101000101 | 0 |
|
||||
| 2345 | 0 | 100001101000101 | 0 |
|
||||
| 0 | 1 | 100000000000000 | 12345 |
|
||||
| 0 | 1 | 100000000000000 | 0 |
|
||||
| 0 | 1 | 110000000000000 | 75 |
|
||||
| 12345 | 1 | 000111111001111 | 0 |
|
||||
| 12345 | 1 | 000111111001111 | 12345 |
|
||||
| 12345 | 1 | 010111111001111 | 0 |
|
||||
| 12345 | 1 | 010111111001111 | 12345 |
|
||||
| -1 | 1 | 100111111001111 | -1 |
|
||||
| -1 | 1 | 101000001001111 | -1 |
|
||||
| -1 | 1 | 000111111001111 | 12345 |
|
||||
| -1 | 1 | 010111111001111 | 12345 |
|
||||
| -1 | 0 | 100111111001110 | 0 |
|
||||
| -1 | 0 | 100111111001101 | 0 |
|
||||
| -1 | 0 | 100111111001011 | 0 |
|
||||
| -1 | 0 | 100111111000111 | 0 |
|
||||
| -1 | 0 | 100111111011111 | 0 |
|
||||
| -1 | 0 | 100111111101111 | 0 |
|
||||
| -1 | 0 | 100111110001111 | 0 |
|
||||
| -1 | 0 | 100111101001111 | 0 |
|
||||
| -1 | 0 | 100111011001111 | 0 |
|
||||
| -1 | 0 | 100110111001111 | 0 |
|
||||
| -1 | 0 | 100101111001111 | 0 |
|
||||
| -1 | 0 | 100011111001111 | 0 |
|
||||
| -1 | 0 | 101111111001111 | 0 |
|
||||
| -1 | 0 | 110000000000000 | 89 |
|
||||
29
original/projects/5/Memory.hdl
Normal file
29
original/projects/5/Memory.hdl
Normal file
@@ -0,0 +1,29 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/5/Memory.hdl
|
||||
/**
|
||||
* The complete address space of the Hack computer's memory,
|
||||
* including RAM and memory-mapped I/O.
|
||||
* The chip facilitates read and write operations, as follows:
|
||||
* Read: out(t) = Memory[address(t)](t)
|
||||
* Write: if load(t-1) then Memory[address(t-1)](t) = in(t-1)
|
||||
* In words: the chip always outputs the value stored at the memory
|
||||
* location specified by address. If load=1, the in value is loaded
|
||||
* into the memory location specified by address. This value becomes
|
||||
* available through the out output from the next time step onward.
|
||||
* Address space rules:
|
||||
* Only the upper 16K+8K+1 words of the Memory chip are used.
|
||||
* Access to address>0x6000 is invalid. Access to any address in
|
||||
* the range 0x4000-0x5FFF results in accessing the screen memory
|
||||
* map. Access to address 0x6000 results in accessing the keyboard
|
||||
* memory map. The behavior in these addresses is described in the Screen
|
||||
* and Keyboard chip specifications given in the lectures and the book.
|
||||
*/
|
||||
CHIP Memory {
|
||||
IN in[16], load, address[15];
|
||||
OUT out[16];
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
}
|
||||
191
original/projects/5/Memory.tst
Normal file
191
original/projects/5/Memory.tst
Normal file
@@ -0,0 +1,191 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/05/Memory.tst
|
||||
|
||||
// Tests the Memory chip by inputting values to selected addresses,
|
||||
// verifying that these addresses were indeed written to, and verifying
|
||||
// that other addresses were not accessed by mistake. In particular, we
|
||||
// focus on probing the registers in addresses 'lower RAM', 'upper RAM',
|
||||
// and 'Screen', which correspond to 0, %X2000, and %X4000 in Hexadecimal
|
||||
// (0, 8192 (8K), and 16385 (16K+1) in decimal).
|
||||
|
||||
load Memory.hdl,
|
||||
output-file Memory.out,
|
||||
compare-to Memory.cmp,
|
||||
output-list in%D1.6.1 load%B2.1.2 address%B1.15.1 out%D1.6.1;
|
||||
|
||||
echo "Before you run this script, select the 'Screen' option from the 'View' menu";
|
||||
|
||||
// We've noticed a common design mistake in several students' Memory.hdl files.
|
||||
// This error leads to zeros being written in the offset of inactive memory segments
|
||||
// instead of the intended location. To identify this issue, the test should check not
|
||||
// only for incorrect writes into the wrong segment but also for any unexpected changes.
|
||||
// To prepare for this, we've initialized the memory with a specific number in the areas
|
||||
// where these erroneous writes might happen.
|
||||
|
||||
//// Sets RAM[2000], RAM[4000] = 12345 (for the following overwrite test)
|
||||
set in 12345, set load 1, set address %X2000, tick, output; tock, output;
|
||||
set address %X4000, tick, output; tock, output;
|
||||
|
||||
set in -1, // Sets RAM[0] = -1
|
||||
set load 1,
|
||||
set address 0,
|
||||
tick,
|
||||
output;
|
||||
tock,
|
||||
output;
|
||||
|
||||
set in 9999, // RAM[0] holds value
|
||||
set load 0,
|
||||
tick,
|
||||
output;
|
||||
tock,
|
||||
output;
|
||||
|
||||
set address %X2000, // Did not also write to upper RAM or Screen
|
||||
eval,
|
||||
output;
|
||||
set address %X4000,
|
||||
eval,
|
||||
output;
|
||||
|
||||
//// Sets RAM[0], RAM[4000] = 12345 (for following overwrite test)
|
||||
set in 12345, set load 1, set address %X0000, tick, output; tock, output;
|
||||
set address %X4000, tick, output; tock, output;
|
||||
|
||||
set in 2222, // Sets RAM[2000] = 2222
|
||||
set load 1,
|
||||
set address %X2000,
|
||||
tick,
|
||||
output;
|
||||
tock,
|
||||
output;
|
||||
|
||||
set in 9999, // RAM[2000] holds value
|
||||
set load 0,
|
||||
tick,
|
||||
output;
|
||||
tock,
|
||||
output;
|
||||
|
||||
set address 0, // Did not also write to lower RAM or Screen
|
||||
eval,
|
||||
output;
|
||||
set address %X4000,
|
||||
eval,
|
||||
output;
|
||||
|
||||
set load 0, // Low order address bits connected
|
||||
set address %X0001, eval, output;
|
||||
set address %X0002, eval, output;
|
||||
set address %X0004, eval, output;
|
||||
set address %X0008, eval, output;
|
||||
set address %X0010, eval, output;
|
||||
set address %X0020, eval, output;
|
||||
set address %X0040, eval, output;
|
||||
set address %X0080, eval, output;
|
||||
set address %X0100, eval, output;
|
||||
set address %X0200, eval, output;
|
||||
set address %X0400, eval, output;
|
||||
set address %X0800, eval, output;
|
||||
set address %X1000, eval, output;
|
||||
set address %X2000, eval, output;
|
||||
|
||||
set address %X1234, // RAM[1234] = 1234
|
||||
set in 1234,
|
||||
set load 1,
|
||||
tick,
|
||||
output;
|
||||
tock,
|
||||
output;
|
||||
|
||||
set load 0,
|
||||
set address %X2234, // Did not also write to upper RAM or Screen
|
||||
eval, output;
|
||||
set address %X6234,
|
||||
eval, output;
|
||||
|
||||
set address %X2345, // RAM[2345] = 2345
|
||||
set in 2345,
|
||||
set load 1,
|
||||
tick,
|
||||
output;
|
||||
tock,
|
||||
output;
|
||||
|
||||
set load 0,
|
||||
set address %X0345, // Did not also write to lower RAM or Screen
|
||||
eval, output;
|
||||
set address %X4345,
|
||||
eval, output;
|
||||
|
||||
//// Clears the overwrite detection value from the screen
|
||||
set in 0, set load 1, set address %X4000, tick, output; tock, output;
|
||||
|
||||
// Keyboard test
|
||||
|
||||
set address 24576,
|
||||
echo "Click the Keyboard icon and hold down the 'K' key (uppercase) until you see the next message...",
|
||||
// It's important to keep holding the key down since if the system is busy,
|
||||
// the memory will zero itself before being outputted.
|
||||
|
||||
while out <> 75 {
|
||||
tick, tock, // tick, tock prevents hang if sync. parts used in KB path.
|
||||
}
|
||||
|
||||
clear-echo,
|
||||
output;
|
||||
|
||||
// Screen test
|
||||
|
||||
//// Sets RAM[0FCF], RAM[2FCF] = 12345 (for following overwrite test)
|
||||
set in 12345, set load 1, set address %X0FCF, tick, output; tock, output;
|
||||
set address %X2FCF, tick, output; tock, output;
|
||||
|
||||
set load 1,
|
||||
set in -1,
|
||||
set address %X4FCF,
|
||||
tick,
|
||||
tock,
|
||||
output,
|
||||
|
||||
set address %X504F,
|
||||
tick,
|
||||
tock,
|
||||
output;
|
||||
|
||||
set address %X0FCF, // Did not also write to lower or upper RAM
|
||||
eval,
|
||||
output;
|
||||
set address %X2FCF,
|
||||
eval,
|
||||
output;
|
||||
|
||||
set load 0, // Low order address bits connected
|
||||
set address %X4FCE, eval, output;
|
||||
set address %X4FCD, eval, output;
|
||||
set address %X4FCB, eval, output;
|
||||
set address %X4FC7, eval, output;
|
||||
set address %X4FDF, eval, output;
|
||||
set address %X4FEF, eval, output;
|
||||
set address %X4F8F, eval, output;
|
||||
set address %X4F4F, eval, output;
|
||||
set address %X4ECF, eval, output;
|
||||
set address %X4DCF, eval, output;
|
||||
set address %X4BCF, eval, output;
|
||||
set address %X47CF, eval, output;
|
||||
set address %X5FCF, eval, output;
|
||||
|
||||
set load 0,
|
||||
set address 24576,
|
||||
echo "Two horizontal lines should be in the middle of the screen. Hold down 'Y' (uppercase) until you see the next message ...",
|
||||
// It's important to keep holding the key down since if the system is busy,
|
||||
// the memory will zero itself before being outputted.
|
||||
|
||||
while out <> 89 {
|
||||
tick, tock, // tick, tock prevents hang if sync. parts used in KB path.
|
||||
}
|
||||
|
||||
clear-echo,
|
||||
output;
|
||||
25
original/projects/5/Rect.hack
Normal file
25
original/projects/5/Rect.hack
Normal file
@@ -0,0 +1,25 @@
|
||||
0000000000000000
|
||||
1111110000010000
|
||||
0000000000010111
|
||||
1110001100000110
|
||||
0000000000010000
|
||||
1110001100001000
|
||||
0100000000000000
|
||||
1110110000010000
|
||||
0000000000010001
|
||||
1110001100001000
|
||||
0000000000010001
|
||||
1111110000100000
|
||||
1110111010001000
|
||||
0000000000010001
|
||||
1111110000010000
|
||||
0000000000100000
|
||||
1110000010010000
|
||||
0000000000010001
|
||||
1110001100001000
|
||||
0000000000010000
|
||||
1111110010011000
|
||||
0000000000001010
|
||||
1110001100000001
|
||||
0000000000010111
|
||||
1110101010000111
|
||||
Reference in New Issue
Block a user