Project 1
Project 1
Prof. Forsyth
1 Requirements
• Download the proper version of CircuitSim. The proper version is version 1.9.1 or later. You download
it from the CircuitSim website (https://ra4king.github.io/CircuitSim/). To run CircuitSim, Java must
be installed. If you are a Mac user, you may need to right-click on the JAR file and select “Open” in
the menu to bypass Gatekeeper restrictions.
• CircuitSim is still under development and may have unknown bugs. Please back up your work using
some form of version control, such as a local/private git repository or Dropbox. Do not use public
git repositories; it is against the Georgia Tech Honor Code.
• The LC-4000 assembler is written in Python. If you do not have Python 3 or newer installed on your
system, you must install it before you continue. You may also use the Docker container for this.
3 Grading
Grading will be done via submission to the project 1 autograder on gradescope. Each operation and certain
parts of the datapath you implement will be worth an equivalent number of points. There will also be points
for fully completing the project via completing a successful run of pow.s, which is provided to you. TAs
will review your submission and add/remove points due to circumstances not reflected by the autograder.
Note: The autograder will have a limit to the daily number of submissions until one day before the due
date, as it is not meant to be a debugger. See Section 7 for more details about gradescope and how to
debug locally.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
In this phase of the project, you must learn the Instruction Set Architecture (ISA) for the processor we will
be implementing. Afterwards, we will implement a complete LC-4000 datapath in CircuitSim using what
you have just learned.
You must do the following:
1. Learn and understand the LC-4000 ISA. The ISA is fully specified and defined in Appendix A: LC-4000
Instruction Set Architecture. Do not move on until you have fully read and understood the
ISA specification. Every single detail will be relevant to implementing your datapath in the next
step.
2. Using CircuitSim, implement the LC-4000 datapath. To do this, you will need to use the details of the
LC-4000 datapath defined in Appendix A: LC-4000 Instruction Set Architecture. You should model
your datapath on Figure 1.
3. Put your name on your CircuitSim data path in a comment box so we know it is your work.
4.1 Hints
4.1.1 Subcircuits
CircuitSim enables you to break create reusable components in the form of subcircuits. We highly rec-
ommend that you break parts of your design up into subcircuits. At a minimum, you will want to
implement your ALU in a subcircuit, but we highly recommend using more. The control unit you implement
in Phase 2 is another prime candidate for a subcircuit.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
4.1.2 Debugging
As you build the datapath, you should consider adding functionality to allow you to operate the whole
datapath by hand. This will make testing individual operations quite simple. We suggest your datapath
include devices (such as probes) to view the values at different parts of your datapath as it runs a program.
Feel free to add any additional hardware that will help you understand what is going on. Using breakpoints
to pause the program at a specified point can be very helpful.
2. Implement the Microcontrol Unit using CircuitSim. The appendix contains all of the necessary in-
formation. Take note that the input and output signals on the schematics directly match the signals
marked in the LC-4000 datapath schematic (see Figure 1).
We highly recommend using test programs that contain a single instruction since you are bound to
have a few bugs at this stage of the project. Once you have built confidence, test your processor with
the provided pow.s program as a more comprehensive test case.
Important: When copying and pasting hex into CircuitSim sub-circuits, be sure to double-click into the
sub-circuit from the Datapath circuit page, and then paste the values into any ROMs, otherwise, the hex
will not persist once you exit the sub-circuit.
Warning: The Excel sheet has multiple columns filled with formulas. Be sure not to change the equations,
or the hex will not be computed accurately. Be especially careful about this when copying and pasting within
the sheet.
7 Autograder
The gradescope autograder will execute a series of tests that will help determine your grade on this project:
1. A test that verifies you implemented the zero register correctly.
2. A set of unit tests that verify you implemented the instructions correctly.
3. A comprehensive test that runs pow.s.
Feel free to use it as a tool to assist you debug your circuit, but you should not rely on it entirely. The
autograder message may not pinpoint your problem, and local debugging is the only way to find the issue.
You must adhere to the following rules, or you will be penalized and the gradescope autograder will not run
correctly:
• Don’t rename the main subcircuit ”Datapath”
• Name your PC register as “PC”
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
8 Deliverables
To submit your project, you need to upload the following files to Gradescope:
• CircuitSim Datapath file (LC-4000.sim)
• Microcode file (microcode.xlsx)
If you are missing one or both of those files, you will get a 0 so make sure that you have
uploaded both of them.
Always re-download your assignment from Gradescope after submitting to ensure that all
necessary files were properly uploaded. If what we download does not work, you will get a 0
regardless of what is on your machine.
This project will be demoed. To receive full credit, you must sign up for a demo slot and
complete the demo. Demo information will be released on Canvas near the due date.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
9.1 Registers
The LC-4000 has 16 general-purpose registers. While there are no hardware-enforced restraints on the uses
of these registers, your code is expected to follow the conventions outlined below.
7. Register 12 is reserved for handling interrupts. While it should be implemented, it otherwise will not
have any special use on this assignment.
8. Register 13 is the everchanging top of the stack; it keeps track of the top of the activation record for
a subroutine.
9. Register 14 is the anchor point of the activation frame. It is used to point to the first address on the
activation record for the currently executing process.
10. Register 15 is used to store the address a subroutine should return to when it is finished executing.
Operation
DR = SR1 + SR2;
Description
The ADD instruction obtains the first source operand from the SR1 register. The second source operand is
obtained from the SR2 register. The second operand is added to the first source operand, and the result is
stored in DR.
9.3.2 NAND
Assembler Syntax
NAND DR, SR1, SR2
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
DR = ~(SR1 & SR2);
Description
The NAND instruction performs a logical NAND (AND NOT) on the source operands obtained from SR1
and SR2. The result is stored in DR.
HINT: A logical NOT can be achieved by performing a NAND with both source operands the same.
The following assembly:
NAND DR, SR1, SR1
achieves the following logical operation: DR ← SR1.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
9.3.3 ADDI
Assembler Syntax
ADDI DR, SR1, immval20
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
DR = SR1 + SEXT(immval20);
Description
The ADDI instruction obtains the first source operand from the SR1 register. The second source operand is
obtained by sign-extending the immval20 field to 32 bits. The resulting operand is added to the first source
operand, and the result is stored in DR.
9.3.4 LW
Assembler Syntax
LW DR, offset20(BaseR)
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
DR = MEM[BaseR + SEXT(offset20)];
Description
An address is computed by sign-extending bits [19:0] to 32 bits and then adding this result to the contents
of the register specified by bits [23:20]. The 32-bit word at this address is loaded into DR.
9.3.5 SW
Assembler Syntax
SW SR, offset20(BaseR)
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
MEM[BaseR + SEXT(offset20)] = SR;
Description
An address is computed by sign-extending bits [19:0] to 32 bits and then adding this result to the contents
of the register specified by bits [23:20]. The 32-bit word obtained from register SR is then stored at this
address.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
9.3.6 BEQ
Assembler Syntax
BEQ SR1, SR2, offset20
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
if (SR1 == SR2) {
PC = incrementedPC + offset20
}
Description
A branch is taken if SR1 is equal to SR2. If this is the case, the PC will be set to the sum of the incremented
PC (since we have already undergone fetch) and the sign-extended offset[19:0].
9.3.7 JALR
Assembler Syntax
JALR AT, RA
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0110 AT RA unused
Operation
RA = PC;
PC = AT;
Description
First, the incremented PC (address of the instruction + 1) is stored in register RA. Next, the PC is loaded
with the value of register AT, and the computer resumes execution at the new PC.
9.3.8 HALT
Assembler Syntax
HALT
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0111 unused
Description
The machine is brought to a halt and executes no further instructions.
Note: The autograder will not run if this instruction is not implemented correctly.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
9.3.9 BLT
Assembler Syntax
BLT SR1, SR2, offset20
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
if (SR1 < SR2) {
PC = incrementedPC + offset20
}
Description
A branch is taken if SR1 is less than SR2. If this is the case, the PC will be set to the sum of the incremented
PC (since we have already undergone fetch) and the sign-extended offset[19:0].
9.3.10 LEA
Assembler Syntax
LEA DR, label
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
DR = PC + SEXT(PCoffset20);
Description
An address is computed by sign-extending bits [19:0] to 32 bits and adding this result to the incremented
PC (address of instruction + 1). It then stores the computed address in the register DR.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
9.3.11 MIN
Assembler Syntax
MIN DR, SR1, SR2
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
if (SR1 < SR2) {
DR = SR1
} else {
DR = SR2
}
Description
The minimum is computed between the values in both source registers. It then stores the minimum value
in the register DR.
Note: MIN and MAX have the same opcode. Bit 4 being 0 indicates the MIN instruction.
The control flow for MIN must go through the CC ROM. Not doing so will cause you to
lose points!
9.3.12 MAX
Assembler Syntax
MAX DR, SR1, SR2
Encoding
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Operation
if (SR1 > SR2) {
DR = SR1
} else {
DR = SR2
}
Description
The maximum is computed between the values in both source registers. It then stores the maximum value
in the register DR.
Note: MIN and MAX have the same opcode. Bit 4 being 0 indicates the MAX instruction.
The control flow for MAX must go through the CC ROM. Not doing so will cause you to
lose points!
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
As you can see, there are three different locations that the next state can come from: part of the output
from the previous state (main ROM), the sequencer ROM, and the condition ROM. The mux controls which
of these sources gets through to the state register. If the previous state’s “next state” field determines where
to go, neither the OPTest nor ChkCmp signals will be asserted. If the opcode from the IR determines the
next state (such as at the end of the FETCH state), the OPTest signal will be asserted. If the comparison
circuitry determines the next state (such as in the BEQ instructions), the ChkCmp signal will be asserted.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
Note that these two signals should never be asserted at the same time since nothing is input into the “11”
pin on the MUX.
The sequencer ROM should have one address per instruction, and the condition ROM should have one
address for condition true and one for condition false.
Before getting down to specifics you need to determine the control scheme for the datapath. To do this
examine each instruction, one by one, and construct a finite state bubble diagram showing exactly what
control signals will be set in each state. Also determine what are the conditions necessary to pass from one
state to the next. You can experiment by manually controlling your control signals on the bus you’ve created
in Phase 1 - Implement the Datapath to make sure that your logic is sound.
Once the finite state bubble diagram is produced, the next step is to encode the contents of the Control Unit
ROM. Then you must design and build (in CircuitSim) the Control Unit circuit which will contain the three
ROMs, a MUX, and a state register. Your design will be better if it allows you to single step and ensure
that it is working properly. Finally, you will load the Control Unit’s ROMs with the hexadecimal generated
by your filled out microcode.xlsx.
Note that the input address to the ROM uses bit 0 for the lowest bit of the current state and 5 for the
highest bit for the current state.
Project 1 CS 2200 - Computer Systems and Networks Fall 2024
Note: The ordering of RegSelHi/RegSelLo and ALU2/ALU1/ALU0 are in the opposite order in the
microcode excel spreadsheet! Please make sure you are enabling the correct signals in your microcode!
Project 1 CS 2200 - Computer Systems and Networks Fall 2024