ECE 374: Computer Organization

Lab 2: Add/Sub Processor

Requirements

Objective: Upgrade the current MIPS processor to incorporate subtract instructions and encoding instructions into the processor for simulation.

Learning Outcomes:

Theory (RCA to add_sub):

Currently, the microprocessor is equipped with a 4-bit Ripple Carry Adder (RCA) as shown below.

To incorporate addition and subtraction both, the RCA needs to be upgraded to an add_sub circuit, as shown below.

This circuit can perform both addition and subtraction. For addition, set Cin=0. For subtraction, set Cin=1.

This circuit was designed and simulated for Lab1.

Theory (encoding):

In MIPS, instructions are 32-bits long. R-type instructions are used for register-to-register operations like addition or subtraction. These instructions break down into the following 6 fields:

Encoding Example: 𝐴𝑑𝑑 𝑅3,𝑅2,𝑅

This means we add the values in R2 and R4 and store the result in R3.

Here’s how this instruction looks in binary:

Opcode (6-bits) Rs (5-bits) Rt (5-bits) Rd (5-bits) Shamt (5-bits) Funct (6-bits)
R-Type R R R Not used Addition
000000 00010 00100 00011 00000 100000

Machine Code: 00000_00010_00100_00011_00000_100000

Prelab:

Pre 1: Encode the instructions into machine code.

Pre 2: Calculate the expected output.

Lab Procedure:

Step 1: Open the project using Vivado.

Step 2: Compile the project. To ensure that all files were downloaded correctly, run the project once.

No need to run simulation, if there are any errors contact the instructor.

Step 3: Open the RCA’s VHDL file

Step 4: Modify the RCA code to add_sub circuit.

You can refer/use the code from Lab 1 for this portion (Full Adder code is not required).

Do not change any naming such as “ripple_carry” or any of the input names.

Move to the next step if there are no errors.

Step 5: Open the Instruction Memory’s VHDL file

Step 6: Input the encoded instructions into the VHDL file

The constants im0, im1, im2, ...., im15 represents memory locations 0, 1, 2, ..., 15.

Use the format as shown in the sample instructions, doing so allows us to put “_” to create spacing between the different fields of the 32-bit instruction.

Step 7: Compile and run simulation

Each program counter value represents one instruction. i.e. PC=1 is instruction 1.

Note:

  • You can get rid of the internal waves by selecting the wave and deleting it.
  • You only need: clock, reset, current_pc and result, everything else is for debugging.

Move to the next step if the simulation matches with the expected output (Prelab 2).

Step 8: Program the FPGA board

Step 9: Run the processor on the FPGA Board.

Prelab

Initial conditions:

Expected output:

VHDL Code