Project 4: Processor Design
your classmates probably have the same questions you do and would benefit from seeing the TA's answer in a public forum!
Posted: 20-Mar-2006 Updates
Portions of the text which have been updated are shown in red.
LogisimWARNING: Logisim is much more stable than it was last semester, but it still does crash from time to time. Save your work often. Also, make a copy of your work from time to time in case a bug in logisim corrupts your saved file.We have extended Logisim 2.0.4 with an additional type of gate for this project. You can start our extended version of Logisim with this command:
java -jar ~cs61c/projs/04/logisim-ucb-2.jar
Our extension to Logisim add a new gate type, called "software", which uses software code to simulate a piece of hardware that has not yet been designed. The source code for this new gate is in the .jar file if you are curious. SimulationWhen building large, complex systems, digital designers will often simulate individual components of the system (both in isolation and together), and then reimplement those components in hardware. Some technologies, like RDL let you test a system containing a mix of hardware and software components.In this project you will complete the following design tasks:
The advantage of this design method is that task #1 is much easier than going directly to an all-hardware-gate design, so you're likely to get to a "correct" solution much more quickly. Furthermore, fixing bugs in the software stage is easier than fixing them once you've turned everything into gates. Once you arrive at a "correct" solution, you can incrementally convert it into hardware, testing as you go to make sure that you never break the "correctness" of your CPU. Important DistinctionIt is very important to understand the distinction between these software components and the actual hardware gates you will convert them into. Unrestricted C code, like the kind you will be writing, cannot be turned into hardware -- you can't drop off a bunch of C code at an IC foundry or an FPGA vendor and expect to get back a CPU!However, writing software in popular languages like C or Java is often an easy way of prototyping a system before undertaking the effort of a detailed hardware implementation. ISAYou will be implementing a simple 8-bit processor with only two registers. Your processor will have separate instruction and data memory.The instruction encoding is given below. You can determine which instruction a byte encodes by looking at the top bits. +-----+-----+-----+-----+-----+-----+-----+-----+ | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 0 0 0 | 0 | 0 | rd | ra | rb | or: $rd = $ra | $rb | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 0 0 0 | 0 | 1 | rd | ra | rb | add: $rd = $ra + $rb | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 0 0 0 | 1 | 0 | rd | ra | rb | and: $rd = $ra & $rb | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 0 0 0 | 1 | 1 | rd | ra | rb | sub: $rd = $ra - $rb | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 0 0 1 | rd | immediate | lw: $rd = MEM[imm] | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 0 1 0 | rd | immediate | sw: MEM[imm] = $rd | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 0 1 1 | rd | immediate | lui: $rd = imm << 4 | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 1 0 0 | rd | immediate | ori: $rd = $rd | imm | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 1 0 1 | address | j | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+ | 1 1 0 | offset | beq | +-----+-----+-----+-----+-----+-----+-----+-----+----------------------+The beq instruction's offset argument is a signed offset relative to the instruction following the current instruction, just as in MIPS. Specifically, if PC is the program counter, then beq does this: if $ra == $rb then PC = PC + 1 + offset else PC = PC + 1The jump instruction also only changes the bottom 5 bits of the PC (since only that many can be specified in the address -- which is an unsigned number): PC = (PC & 0xE0) | address TestingYou will need to write a program which multiplies the number in the first byte of memory (0x00) with the number in the second byte of memory (0x01) and stores the result in the third byte of memory (0x02). You do not need to handle signed numbers or overflow. You also do not need to preserve the values stored in the first two bytes of memory; if you find it convenient to change those values during the course of computing the result, you may do so.
The last instruction in your program should be a
one-instruction infinite loop (an instruction which unconditionally
jumps to itself -- an idiom for "HALT").
Once you create a gate, you must set its filename property to
the name of a .c source code file in the directory where
you were when you typed the command to launch Logisim. Logisim
will automatically compile your code and run it; when you modify the
file (and save it), Logisim will notice and recompile your code.
Your C code must follow a very specific pattern; make a copy of
~cs61c/projs/04/template.c and:
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" and "load" 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!)
To make a RAM work properly, you must:
HintsYou can use the Project->LoadLibrary menu option to load several of the Logisim built-in libraries. One of them (Arithmetic) includes adders, subtractors, and comparators that you will probably find useful.Always leave open the terminal window in which you typed the command to start Logisim! This is important; any errors compiling or running your C code will be reported here, and we will need this output to diagnose any problems you might have. Furthermore, you can use printf() in your C code to display intermediate results; anything you pass to printf() will be displayed in the terminal window. Logisim can build combinational circuits for you automatically from boolean equations; this is useful for generating control circuitry. See the "Combinational Analysis" option on the "Window" menu. Hand-inYour CPU must implement the full instruction set shown above."Readability" will be part of the grade. When the readers grade the design, without much effort, they should immediately see what a region of the circuit does. Your design should be sensibly organized into subcircuits; putting too many things in a single circuit makes it very difficult to understand. You must hand in these files:
To turn in your assignment, type:
submit proj4
Note on connecting two software gates directly to each otherIf you connect two software gates directly to each other, you will need to put a "buffer" on the wire between them facing in the direction in which data is supposed to flow. Make sure that the "bit width" of the buffer is set correctly.Nearly all logisim gates other than the "software gate" require you to manually specify the bit width. I designed the software gate to auto-detect this to save you time, but if you connect two software gates to each other there's nothing to detect from. So you have to stick something in there to "force" the bitwidth. A buffer is just a gate that does nothing (copies its input to its output) but it forces both the bitwidth on the wire as well as the direction that data should flow. |