Lab 5: Decode Unit Components

In this lab, you have two new components to build.

Decoder Unit

This unit is a mess to build, so take it slowly. Work with your team, and add one instruction at a time. You should test things as you go.

The decode unit takes two 16-bit uint16_t instruction data values in and produces several output results. If we start with the ADD instruction, we will generate two register numbers, and a code for the ALU operation we want. This code is up to you to pick.


You might use a C++ enumeration for this (look this up if you have never seen it, it is a neat way to use names instead of numbers for places like this.)

For this lab, focus on the basic instructions the ALU needs to support:

  • ADD
  • SUB
  • AND
  • OR
  • NOT (COM)
  • EOR

All of these are single instruction word operands, and all reference registers. Remember that you need to update the PC as part of this work.

Register Memory

The register memory is very similar to the instruction memeory you constructed for the last lab, You need to set up an array of uint8_t data items for this memory component, and we need exactly 32 items, so set this up as a simple array.

Add signals to control reading and writing. It is common to keep these separate, but you can use a single line if you wish.

The tick method will need to check the read signal to verify that it is doing a read. It will then use the two incoming register number signals to access the register memory, delivering two results to the output pins that we will connect up to the ALU in our next lab.

When we are writing, we need one other input line, holding data that will be delivered later by the store stage. That data will be recorded into memeory using the register number indicated in the instruction (usually the Rd register).

Again, write test code to verify that your unit is working properly.