For this project you will implement a data path which fetches 8-bit instructions from memory and executes them. Details on what components your datapath must have as well as the instructions you must implement can be found below. The project will be due by the end of the day, Tuesday, August 8. The associated Homework 6 will be due by the end of the day, Saturday, August 5.
You will be using Logisim 2 for this project. You can run it on the instructional machines by typing java -jar ~cs61c/bin/logisim.jar and you can download it to your home machine from the Logisim Website.
Logisim 2 is more stable than it used to be (if you've heard rumors), but you should still be careful when using it. Some useful tips:
1. Save early, save often, make backups. This software will crash on you. Be prepared for this to happen. In addition, make sure you make fairly frequent backups of your files, as you may hit a bug that corrupts your file.
2. A tutorial/user guide is now available from the Logisim developer.
3. Feel free to run Logisim at home. As it is writen in Java you should be able to run it with the same results anywhere.
You must submit your CPU (named cpu.circ) and your sample program (named sum.code) online. Do this by creating a directory called proj3, creating your files, and typing submit proj3.
Readability is an important factor in your grade for this project. You should start by creating sub-circuits for the various processor components you will need. The final design should be a combination of these subcircuits that is as easy to understand as possible.
You should begin your work on this project by creating your ALU. You must turn in your ALU by the end of the day, Saturday, August 5 as a checkpoint along the way to completing the project and to recieve credit for Homework 6. Do this by creating a file called alu.circ and typing submit hw6 from the directory that contains it. As with the full CPU, readability is essential in this circuit.
You will have separate instruction and data memories (thus prohibitting self-modifying code). Logisim provides a memory module which you can use.The instruction memory is 8 bits wide and addressed with 8 bits (thus 256 instruction memory locations). The data memory is also 8 bits wide but is only addressed with 4 bits (thus there are only 16 data memory locations). We use byte addressing.
You can change the contents of a logisim RAM module by choosing the "poke" tool (the little hand). Double click on the memory cell you want to change and type the new value in hexadecimal.
You can also save the contents of a RAM to a file and load it back by right-clicking on the RAM and using the "Save Image" and "Load Image" menu options. Once you've saved a RAM file, you can edit it with a text editor; each line is a one-byte hexadecimal value (don't mess with the header!). A sample file has been provided.
To make a RAM work properly, you must:
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
op | rd | rs1 | rs2 | func |
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
op | rd | imm |
Instruction | Opcode | Function code | meaning |
---|---|---|---|
or $rd,$rs1,$rs2 | 0 | 0 | R[rd] = R[rs1] | R[rs2]; PC = PC + 1 | add $rd,$rs1,$rs2 | 0 | 1 | R[rd] = R[rs1] + R[rs2]; PC = PC + 1 | and $rd,$rs1,$rs2 | 0 | 2 | R[rd] = R[rs1] & R[rs2]; PC = PC + 1 | sub $rd,$rs1,$rs2 | 0 | 3 | R[rd] = R[rs1] - R[rs2]; PC = PC + 1 |
Instruction | Opcode | Meaning | .
---|---|---|
load $rd,imm | 1 | R[rd] = MEM[imm]; PC = PC + 1 |
store $rd,imm | 2 | MEM[imm] = R[rd]; PC = PC + 1 |
lui $rd,imm | 3 | R[rd] = {imm, 0000}; PC = PC + 1 |
ori $rd,imm | 4 | R[rd] = R[rd] | zero_extended(imm); PC = PC + 1 |
jeq imm | 5 | if R[0] == R[1] then PC = {upper_four_bits(PC), imm} else PC = PC + 1 |
j imm | 6 | PC = {upper_four_bits(PC), imm} |
halt | 7 | nothing happens; PC = PC |
You may use any Logisim components in these libraries (which can be accessed from the Project menu in Logisim): Base, Gates, Plexers, and Memory.
You may not use any components from the Arithmetic library. (And you should avoid the Legacy library.)