Project 6: Mock Exam Problem & Building a Computer

Due Date: Friday, February 16, 2024 at 11:59pm

Learning Objectives

  • Practice taking a mock exam and reflect on how you prepare for exams.
  • Combine the components you've built in previous projects to culminate to a fully working computer.
  • Study the flow of data within a typical computer system.

Introduction

In this project, you will engage in the metacognitive skill of exam preparation and exam taking by completing a mock exam problem in a group. Then, you will share and discuss your approach for preparing for an exam with your group and answer some reflection questions.

The technical part of this project will involve bringing together all of the chips you have worked on in the past few weeks, cumulating to the building of a computer. Specifically, you will be implementing logic for loading the A and D registers, handling logic for jumping for the program counter, and bringing these components together to build the CPU.

Instructions

Navigate to the Project 6 assignment on Canvas. Open the document, read the instructions on the first page, and estimate the amount of time you think it will take you to complete this project. Then, complete parts I, II, and III of the project.

Part I: Mock Exam Problem (10 points)

Each pair or triad of students will set up a 30-minute session outside of class to complete a timed mock exam problem. Time will be allocated in class for each group to connect and coordinate a time to complete the mock exam problem. Once a time has been determined, please make an Ed post with the day and time in which your group will be meeting.

In your 30-minute session, each group will perform the following items:

  1. Setup: 5 minutes
    • Remove as many distractions as possible (e.g., find a quiet space, turn your phone to silent, etc.).
    • Appoint a member to start a timer for your mock exam problem
    • Grab a scrap piece of paper and pen for working through the mock exam problem
    • Pull up the mock exam problem that was emailed to you

  2. Complete the Mock Exam Problem: 10 Minutes

    Spend 10 minutes working through the mock exam problem individually. Treat it as if it was an actual problem on an exam.

  3. Debrief & Reflection: 15 minutes

    After your time is up, discuss how you approached the mock exam problem and what that experience was like for you. As a group, complete the reflection questions in the Project 6.docx document. Each person should write up their responses individually as you discuss you debrief with your group.

Part II: Building a Computer (20 points)

Pulling Project 6 Starter Code

To complete this assignment, you will need to use git to access the starter materials that have been pushed to your repository by the course staff. First, run git status and see if it reports any changes. If you have any, you'll need to commit them before proceeding (git add . followed by git commit -m "Your message here"). Then, run:

After running this command, you have synchronized the local copy of your repository with the copy on the server.

Background

In previous projects, we've built the computer's basic processing and storage devices (ALU and RAM, respectively). In this project, we will put everything together, yielding the complete Hack Hardware Platform. The result will be a general-purpose computer that can run programs written in the Hack machine language.

Overview

Like the previous projects, this project will involve building a set of HDL chips. This time, you will build the highest-level chips in the whole system, culminating with the "Computer" chip itself. As usual, you should construct these chips using the chips listed in previous projects (with a few exceptions noted below), and we recommend going in the order shown.

Chip Name Description Testing
LoadDReg.hdl Logic related to loading the D register. Estimated Difficulty: Easier. Test your chip using the provided LoadDReg.tst (& LoadDReg.cmp) test script.
LoadAReg.hdl Logic related to loading the A register. Estimated Difficulty: Easier. Test your chip using the provided LoadAReg.tst (& LoadAReg.cmp) test script.
JumpLogic.hdl Logic related to the program counter's load and inc signals. Estimated Difficulty: Mediumish. Test your chip using the provided JumpLogic.tst (& JumpLogic.cmp) test script.
CPU.hdl The Hack CPU. Should make use of the previous three chips in your implementation, and we recommend using the ARegister and DRegister built-in chips for the corresponding registers in your implementation (see the Tips section for more information). Estimated Difficulty: Harder. Test your chip using the provided CPU.tst (& CPU.cmp) test script.
Computer.hdl The computer itself! The top-most chip you will implement in this course. Estimated Difficulty: Easier. Test your chip by running Hack programs on it! You can start with the three listed below.

Contract

When run in the hardware simulator, the system you build should be capable of correctly executing programs written in the Hack machine language, as specified in Chapter 4.

Testing

Testing LoadDReg, LoadAReg, JumpLogic and CPU: It's crucial to unit-test these chips before integrating them into the overall Computer chip. We recommend starting with the LoadDReg, LoadAReg, and JumpLogic chips, and then using those to aid your CPU implementation.

Testing Computer: Note that the Hack architecture and Hack machine language go hand-in-hand—that is, the specification of the Hack architecture's behavior (which you are implementing in Computer.hdl) is exactly defined by the rules and specification of Hack machine language. Therefore, the most effective way to test the correctness of Computer.hdl is to try running different Hack machine language programs on it! We provide three test programs that can be used for this purpose, listed below. Note that "running a program" on Computer.hdl consists of inserting that program's instructions on ROM, then starting the simulation. This is essentially like inserting a chip with a single program hard-coded on it into your computer before powering it on, which isn't quite analogous to the way your laptop executes programs, but is actually done in practice for things like microcontrollers and embedded systems. We choose that approach in this project for its simplicity.

For each of the following .hack programs, a corresponding .tst file and .cmp file is provided that will load it into ROM and execute it for you.

Program Description
Add.hack Adds up the two constants 2 and 3 and writes the result in RAM[0]. Recommended script to test: ComputerAdd.tst (& ComputerAdd.cmp).
Max.hack Computes the maximum of RAM[0] and RAM[1] and writes the result in RAM[2]. Recommended script to test: ComputerMax.tst (& ComputerMax.cmp).
Rect.hack Draws a rectangle of width 16 pixels and length RAM[0] at the top left of the screen. Recommended script to test: ComputerRect.tst (& ComputerRect.cmp).

A Note on Testing: For this project, alternative test files are provided, suffixed with -external. That's because the normal test files exploit certain "behind-the-scenes" data exposed by the built-in versions of certain chips (like ARegister and DRegister) to read internal state of your CPU, allowing them to be much more thorough. However, if you would like to forego these built-in chips and use your own implementations instead, you won't have access to that additional testing data from your components, so you would have to use the -external versions which use only the chip's outputs to test. We strongly recommend the former approach, because the -external tests are not as thorough in general (and ARegister, DRegister, etc. have helpful GUI representations you can use for debugging).

Resources

See Chapter 5 for details about the computer's implementation, and refer to Chapter 4 for details about Hack machine language (particularly the encoding of its instructions). Use the HDL Reference or HDL Survival Guide to look up details of the language, and the TDL Reference to look up details about the test scripting language. You may also find the Hack Chip Set reference useful to remember chip interfaces.

Part II Tips

We risk repeating ourselves too much here, but we strongly recommend you use the textbook chapters, specifically Chapter 4 and Chapter 5 (sections 4.2.2, 4.2.3, and 5.3.1 will be especially helpful with some of the details of the assignment).

Implementation Strategy

Complete the computer's construction in the following order:

LoadDReg, LoadAReg, and JumpLogic: These chips implement some of the combinational logic of the CPU, and we provide you tests to help check you understand the specifications correctly. This will hopefully allow you to build the resulting CPU in a more incremental manner (potentially helping catch future bugs).

CPU: This chip can be constructed according to the proposed CPU implementation given in Figure 5.9 of Chapter 5, using the ALU and register chips built in Projects 3 and 4, respectively. However, we recommend using built-in chip-parts instead, in particular ARegister and DRegister. The built-in versions of these two chips have exactly the same interface and functionality as those of the Register chip specified in Chapter 3; however, they feature GUI side-effects that come in handy for testing purposes.

We have chosen to include internal chips (LoadDReg, LoadAReg, JumpLogic) not mentioned in Figure 5.9 of Chapter 5. This might yield a slightly less efficient CPU design, but the added scaffolding will hopefully make implementing the CPU more manageable. We do not recommend creating more internal chips than the ones we provide, though it may be possible (feel free to ask us if you have any particularly intriguing ideas in mind).

Instruction Memory: Use the built-in ROM32K chip. It is similar to the RAM chips you've implemented, but handles the loading of programs for you.

Computer: The top-most Computer chip can be constructed according to the proposed implementation shown in Figure 5.10 of Chapter 5.

Debugging Tips

Due to the interconnected nature of the CPU, it can be difficult to debug when things are not quite working. We've compiled a list of debugging tips and strategies to try to help guide your debugging. We also encourage you to start early and make use of the discussion board and office hours when you find yourself stuck on a particular part. Here are some things you can do to debug your program:

Tools

As usual, you will test your chip implementations using the Hardware Simulator. The following diagram shows an example of testing the Rect.asm program using it.

Submitting Part II

To submit Part II, make sure you commit and push your changes, then tag them as project-6 and push that tag as well:

Lastly, verify that the tag and all your code is uploaded correctly by checking on https://gitlab.cs.washington.edu/ .

Part III: Project 6 Reflection (5 points)

In the document Project 6.docx, record how long the project took you in reality and write a short written reflection about your experience completing this project.

Submitting Your Work

Make sure you have submitted your completed .hdl files on GitLab by following the instructions in the heading above titled "Submitting Part II." Then, save your changes from the Project 6.docx document as a PDF and submit the document to the assignment titled "Project 6: Mock Exam Problem & Building a Computer" on Gradescope. Project 6 will be considered completed once you have followed these steps.