Build the Computer
and Memory
circuits described in Project 5:
N2T: Project 5
Chapter 5 provides the contract for each circuit, i.e. description of its behavior, names and number inputs, names and state of outputs. The API is available here:
The Hack Chipset
a0,b0,out0)
projects/5/a10
Computer
as shown in Figure 5.9 on page 24. At this stage:
Memory
will simply be a single RAM16K
Screen
and Keyboard
Here are the chips you need to use or build at this stage:
Computer
and CPU
:
CPU
circuitCPU
and copy-paste the CPU
circuit from the main canvasComputer
RAM
and ROM
:
Memory
library
Memory
module as specified in Figure 5.6 on p. 17.
Here are the chips you need to use or build at this stage:
Memory
:
Keyboard
:
GCKeyboard.circ (right-click, Save As..)
Keyboard
has the same API as RAM
and Screen
, so it has two extra inputsScreen
:
nand2tetris.jar (from Menu Bar: Project=>Load Library=>Jar Library... as in previous assignment)
Memory Test
:
address | value | meaning |
---|---|---|
16383(0x3FFF) | ABCD | last address of RAM16K |
16384(0x4000) , 24575(0x5FFF) | 0x7FFF | first and last address of Screen ; should see thin lines at upper-left and lower-right corner |
24576(0x6000) | DCBA | address of Keyboard |
Computer
as shown in Figure 5.9 on page 24.
Computer
:
Keyboard
and Screen
Computer Screen Test
:
TwoLines.hex (should see two lines at the top-left and bottom-right corner of screen)
Rect.hex (first column should be filled halfway)
Computer Final Test
:
Memory
:
Memory
circuitComputer
:
Computer
; could consider working in stages as outlined in Logisim sectionComputer Test with Given Test Cases
:
Computer Test with Class Examples
:
Computer Screen Test
:
TwoLines.hack (should see two lines at the top-left and bottom-right corner of screen)
Rect.hack (first column should be filled halfway)
Computer Final Test
:
CPUEmulator
to test the binary programs. Later test the programs on your own computer in Logisim
an in HardwareSimulator
.
Here is how to test in the CPUEmulator
:
HardwareSimulator
but instead run CPUEmulator
n-th
Fibonacci number where f1=1, f2=1, 2, 3, 5, 8, ...
.
Submit fib.xlsx and fib.hex, i.e. Excel file with code and a program/text file that can be loaded on the ROM as given here:
machine_code_examples.xlsx | count_5_1.hex
Show that the Fibonnacci program works in the Logisim computer by computing the 6th Fibonnacci number. Take a screenshot named fib.png that shows the contents of the RAM and ROM after the program has finished. Click here for a binary to hexadecimal converter.
The program should use the following memory cells. Try different values for m1,m2,m3
, including 0.
n
), the rest should be initialized by the program to the correct valuesn
, index of number we need to compute, not modified by the programi
, index of current Fibonaccci numbercurrFib
, value of current Fibonaccci number; when program stops contains the answernextFib
, value of next Fibonaccci number; when program stops has value after the answerNotes on the loop:
while
loopWe are essentially converting the following Java program:
int fibonacci(int n) { int curFib = 1; // value of current fib number int nextFib = 1; // value of next fib number int i = 1; // index of curFib (n=1 computed in curFib) while (i < n) { int newCur = nextFib; // new value for curFib int newNext = curFib + nextFib; // new value for nextFib curFib = newCur; // change/update curFib nextFib = newNext; // change/update nextFib i = i + 1; } return curFib; }
m1,m2,m3 ≥ 0
via repeated addition.
Submit mul.xlsx and mul.hex, i.e. Excel file with code and a program/text file that can be loaded on the ROM as given here:
machine_code_examples.xlsx | count_5_1.hex
The program should use the following memory cells. Try different values for n
, i.e. cell 11, including the required values plus a couple of extra ones:
m1
, not modified by the programm2
, not modified by the programm3
, not modified by the programint multiply(int m1, int m2, int m3) { int result = 0; int count1 = m1; while (count1 > 0) { int count2 = m2; while (count2 > 0) { result = result + m3; count2 = count2 - 1; } count1 = count1 - 1; } return result; }
n ≤ 15
:
___ ___ ___ ___ and so on
Submit draw.xlsx and draw.hex, i.e. Excel file with code and a program/text file that can be loaded on the ROM as given here:
machine_code_examples.xlsx | count_5_1.hex
The program should use the following memory cells. Try different values for n
, i.e. cell 11, including the required values plus a couple of extra ones:
n
, not modified by the program16384
, not modified by the programvoid draw(int n, const int start=16384) { int i = start; int count = n; while (count > 0) { M[i] = -1; i = i + 545; // 16*32+33: skip 16 rows + 1 cell count = count - 1; } }
M[5] = 12
A=12
: store value 12 in AD=A
: store/move A, i.e. 12, in DA=5
: store address 5 in AM=D
: store D, i.e. value 12, in cell 5M[5] = M[5] + 1
A=5
: store address 5 in AM=M+1
: add 1 to cell 5M[5] = M[5] + 10
A=10
: store value 10 in AD=A
: store/move A, i.e. 10, in DA=5
: store address 5 in AM=M+D
: add value 10 to cell 55 = 5 + 6
A=5
: store address 5 in AD=M
: store value of cell 5 in DA=6
: store address 6 in AD=D+M
: compute M[5]+M[6] and store in DA=5
: store address 5 in AM=D
: store D, i.e. the sum, in cell 5