Assignment 3A: Hack Hardware
Due Friday, October 10th, before midnight
This next two assignments will implement a computer based on a Von Neuman architecture. The computer’s design will be based on the architecture and instruction set described in the book The Elements of Computing Systems (called Hack).
We will complete this project in two parts:
-
Part 1: Simulate the chips described in Chapters 1-3
-
Part 2: Simulate the computer (Chapter 5) that can execute the machine code described in Chapter 4
Demo Requirement: Check-in with the TA on either Oct 2 or Oct 3 from 6-8
Update your repository
We will use the same repository as Assignment 1
First, you must accept the pull request on your repository on Github (screenshot).
$ cd cs240-f25-classwork
$ git pull
Your repository should now contain a new folder named A03-Hw.
1. Getting Started
In the file, utils.c, implement the functions dec2bin and bin2dec which convert between 16 bit
binary numbers (stored in an array) and decimal numbers. Feel free to re-use code from A02.
void dec2bin(int input, unsigned char out[16])
{
// todo
}
int bin2dec(unsigned char binary[16], bool isSigned)
{
// todo
return 0;
}
Add code to test_gates.c to test your two functions.
uchar a[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 1,0,0,1};
uchar b[16] = {1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1};
check(bin2dec(a) == 9, "bin2dec");
check(bin2dec(b, true) == -1, "bin2dec signed");
2. Gates
In the file, gates.c, implement the defined gates using only nand() or
other gates that you have previously defined. Your implementations should emulate how
composite gates are built from combining simpler gates together. (Hint: if you are using
an if statement, you are doing something wrong!)
Extend the unit tests in test_gates.c to test your functions.
$ make
$ ./test_gates
Requirements/Hints:
-
The functions in
gates.cfollow the specifications in chapter 1 of The elements of computing systems. -
You may not use if statements in any function! For example,
-
Not should be implemented in terms of Nand
-
And should be implemented in terms of Nand and Not
-
Or should be implemented in terms of nand, Not, And
-
etc
-
-
16 bit versions of gates can use for loops
-
Warning: be careful to call
AndNOTand.andis a C++ keyword.
3. ALU
In the file, alu.c, implement the defined gates using only nand() or
other gates that you have previously defined. Your implementations should emulate how
composite gates are built from combining simpler gates together. (Hint: if you are using
an if statement, you are doing something wrong!)
Extend the unit tests in test_alu.c to test your functions.
$ make
$ ./test_alu
Requirements/Hints:
-
The functions in
alu.cfollow the specifications in chapter 2 of The elements of computing systems. -
You may not use if statements in any functions. Hint: use Mux instead
-
16 bit versions of gates can use for loops
4. Memory
In the files, register.c and ram.h, implement the tick() functions defined in each class.
Bit::tick() has already been implemented for you as an example. Again, you must use previously
defined gates. (Hint: if you are using an if statement, you are doing something wrong!)
Extend the unit tests in test_memory.c to test your functions.
$ make
$ ./test_memory
Requirements/Hints:
-
The functions in
register.candram.hfollow the specifications in chapter 3 of The elements of computing systems. -
You may not use if statements in any functions. Hint: use Mux and DMux instead