Lab 9: Build a Simple Datapath

In this lab, you will build a working datapath for a simple instruction set using some of the larger components we’ve already built in this class. You are provided with a simple program counter that increments with a clock signal, an instruction memory element, an instruction decoder, a register file, and ALU, and data memory. Your job is to connect these components together so they can execute instructions.

Assigned: Monday, October 31

Due: Monday, November 7 by 10:30pm

Groups

• Hamza, Adam W., and Sara
• Sophie and Blake
• Tanner and Fengyuan
• Ana and Kamal
• Hattie and Eli
• Matt and Ryan
• Theo and Linda
• Jacob and Bea
• Devin and Charlie

Part A: Getting Started

First, download datapath.circ and open it with Logisim. Start logisim with the following command:

sw $r2, 0($r0)

This instruciton takes the value in $r2 and stores it at the address 0+$r0. We encode it as 0x01200200. Again we have the immediate bit set, because we’re adding an immediate value of zero. We’re storing, so bit 21 is set. Nothing should be written to any registers, so bit 20 is not set. The destination register doesn’t matter, so it is zero. The first source is $r0 (used in the address) and the second source is$r2. Finally, the immediate is zero in this case, so the instruction ends with 0x00.

Sample Program

Instruction memory is pre-loaded with the following program:

0: addi $r0,$r0, 1
1: add $r1,$r1, $r0 2: j 0 Part A Questions 1. We don’t have a$zero register in this architecture. How can you store the value zero to a register? Pay close attention to the operations supported by our ALU.

2. Instruction sets don’t usually have a dedicated opcode for nop. Instead, they use instructions that have no effect on registers or memory (like addi $r0,$r0, 0). This instruction set has many different ways to encode nop. For example, any operation that has zeros in the four bits 31, 22, 21, and 20 (jump, load, store, and writeback, respectively) will behave like a nop. Write down encodings for at least two additional instructions we could use as nop.

3. This instruction set supports some interesting memory operations that MIPS does not allow. Write encodings for the following instructions:

• Load a value from the location $r0+$r1 and store the result in $r2 • Store the value in$r3 to $r3+$r0
• At least one other memory operation that MIPS does not support. Explain what this instruction does.

Part B: Complete the Datapath

Using the specifications above, complete the implementation of this datapath. I recommend starting with basic ALU instructions that do not use immediate values like add $r0,$r0, $r1. Next, move on to support for addi, ori, and so on. Once you have these basic instructions working, you can modify the program counter loop to support jump instructions. Finally, add load and store operations by integrating the data memory component. You should write simple test programs to make sure your implementation is working at various stages in the process. Don’t wait until you’ve “completed” the datapath to test it! You’ll probably get something wrong, and circuits are hard to debug. You can load a sample program by clicking on lines in instruciton memory with the hand tool. Just start typing hexadecimal values and the digits will gradually fill the available space. You can also right click on the instruction memory element and select Edit Contents, although I have had trouble with this editor before. Once you have a program loaded, click the clock element with the hand tool to toggle the clock on and off. Once you’ve run a program, your registers will probably contain garbage values. Under the Simulate menu, select Reset Simulation to clear registers and the program counter to zero. Part B Questions 1. Write a program that adds 1 to$r0, 2 to $r1, 4 to$r2, and 8 to \$r3, then repeats this process indefinitely. Encode this program using our instruction set and test it. Submit the assembly code and encoded instructions.

2. Write a program that stores the value 0 in address zero, 1 in address 1, 2 in address 2, and so on using an infinite loop. Test your program using your completed datapath. Submit the assembly code and encoded instructions.

3. Write at least one more program that does something interesting using a mix of memory, immediate, and register-only instructions. Submit your assembly, encoded instructions, and an explanation of what the program does.