Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ELEC 374 Digital Systems Engineering

Laboratory Project

Winter 2023

Designing a Simple RISC Computer: Phase 1

1. Objectives

The objective of this project is to design, simulate, implement, and verify a simple RISC Computer (Mini SRC), consisting of a simple RISC processor, memory, and I/O.  Phase 1 of this project consists of the design and Functional Simulation of a part of the Mini SRC datapath.  In this Phase, you will design the necessary logic and simulate the add, sub, mul, div, and, or, shr, shra, shl, ror, rol, neg, and not instructions. The “Select and Encode” logic, “CON  FF”  Logic, “Input/Output” ports, “Memory Subsystem” and  load/store instructions, branch and jump instructions, as well as addi, andi, and ori instructions will be designed and simulated in Phase 2.  The complete datapath is shown in Figure 1.

Design input can be done entirely using VHDL or Verilog, or by using a mixed HDL/schematic approach. For your design  using VHDL/Verilog, consult the  Lecture Slides on VHDL  and Verilog  that  have various examples  including  multiplexers,  encoders,  decoders,  registers,  memory  units,  clock  generation,  state machines, etc. You may also use such components available in the Quartus II Library, which can be configured using the Wizard facility. However, you must design your own advanced multiplication circuitry (32x32 Booth algorithm with  bit-pair  recoding of  multiplier) for the  multiplication  instruction .  Note that you are  not allowed  to  use  simple  arithmetic  operators  in  HDL  languages  for  the Arithmetic Logic Unit (ALU) implementation of this project, such as the adder or subtractor circuitry. However, you may use + or arithmetic operators in the implementation of your multiplication or division circuitry, as the intention here is on the implementation of a particular algorithm discussed in class for multiplication/division operations.

2. Preliminaries

2.1 DataPath: Figure 1 illustrates a simplified single-bus Datapath for the Mini SRC (see Figure 4.2 on page

143 and Figure 4.3 on page 148 of the Lab Reader).  As shown in Figure 1, the datapath consists of a 32-bit bus, BUS. The bus is responsible for transferring the information among different components of the system. There can be only one transaction at a time on a single bus.  There are sixteen 32-bit registers R0 through R15 in the Mini SRC, as discussed in the CPU specification document.  There are also two dedicated 32-bit registers HI and LO for holding the result of a multiplication or a division operation.  The 32-bit Instruction Register, IR, holds the current instruction. The 32-bit Program Counter, PC, points to the address of the next instruction after the execution of the current instruction . PC is incremented by 1 during the instruction fetch, using IncPC control signal in the ALU. You may, however, opt for a hardware incrementer for PC outside ALU. In general, you are welcome to come up with your own ideas and design decisions during the entire CPU design project.

The ALU has two inputs, A and B, and an output, C.  Because the bus can support only one transaction at a time, one of the inputs (A input) to the ALU needs to be stored in the 32-bit temporary register, Y.  As discussed in the CPU Specification document, the ALU supports the addition, subtraction, multiplication, division, shift right, shift right arithmetic, shift left, rotate right, rotate left, logical AND, Logical OR, negate, and NOT operations.  The control signals to the ALU (generated by the Control Unit in Phase 3, as shown in Figure 5) will enforce the required operation. These control signals include ADD, SUB, MUL, DIV, SHR, SHRA, SHL, ROR, ROL, AND, OR, NEG, and NOT control signals, among others.  Note that in Phase 1 and Phase 2, you simulate such control signals. The Z register holds the result of the operation in ALU and will be able to drive the Bus in the next clock cycle when the bus is free.  The Z register is 64-bit long to hold the result of a multiplication (product) or a division (remainder in the higher byte, and quotient in the lower byte) operation temporarily before loading the HI and LO registers.  You may need a multiplexer between the Y register and the A input of the ALU for any other potential input. You may also need to include a simple circuitry (such as a multiplexer) between the ALU output C and the Z register.  Depending on the current instruction in the Instruction Register, IR, this logic selects the output of one of the ALU units to drive the Z register.

The Memory Address register (MAR) holds the address of a memory location.  The Memory Data Register (MDR) holds either the data read from memory, or the data to be written into the memory.  The Select and Encode Logic allows transfer of the contents of a register onto the bus, as well as loading the registers with the contents of the bus.  The CON FF Logic is used to determine if the condition is met to allow branching to take place.  The Input (In.Port) and Output (Out.Port) registers are 32-bit registers each, and are used to connect the CPU to the outside world.

31                                         0

PC

31                                          0

IR


Select and Encode Logic


MAR

31 0

MDR


31 0

In.Port

31 0

Out.Port

63

Z

31


LO

Figure 1: Simplified datapath

As a reminder, the “Select and Encode logic”, “CON FF Logic”, “Input/Output ports”, “Memory Subsystem” and load/store instructions, branch and jump instructions, as well as addi, andi, and ori instructions will be tackled in Phase 2.  The information provided here is for the sake of the completeness in describing the datapath.  More information about these units will be provided in Phase 2.

A Typical Register: Figure 2 shows the block diagram for a typical register, such as R1 (there will be a minor revision to R0 circuitry that we will discuss in Phase 2 when we design the Select and Encode Logic”). The input to the register, BusMuxOut, is coming directly from the bus. The contents of the bus is saved onto the register using the synchronous Clock signal and the R1in signal.  The R1in signal is the control signal that allows the data from the bus to be written into the register R1.  The R1out signal is the control signal that allows the contents of R1 to be placed on the bus, through the BusMuxIn-R1 input (see Figure 3).  The Clear signal is used to reset the registers to a known state.

Clear

Clock

R1in

BusMuxOut

clr

clk

write/enable

input D

R1

output Q

BusMuxIn-R1

Figure 2: A typical register

Bus design: One of the important aspects of the Mini SRC datapath is its bus. The Bus may be implemented by tri-state buffers, or by a multiplexer and an encoder.   Figure 3 shows a typical bus design using the multiplexer/encoder approach.  The Mini SRC Bus is implemented using a 32:1 Multiplexer, BusMux, with five select input signals coming from a 32-to-5 encoder. The idea is to choose only one of the registers R0 to R15, HI, LO, Zhigh, Zlow, PC, MDR, In.Port, or the sign-extended version of the constant C, as the source of the bus. The output of the BusMux is BusMuxOut. The inputs to the 32-to-5 encoder, which could select any of the above registers, are the control signals generated by the Control Unit (in Phase 3) or by the Select and Encode Logic” (in Phase 2).  However, in Phase 1, we just simulate these signals.

BusMuxIn-R0

BusMuxIn-R1

BusMuxIn-R15

BusMuxIn-HI

BusMuxIn-LO

BusMuxIn-Zhigh BusMuxIn-Zlow BusMuxIn-PC

BusMuxIn-MDR

z

32

32

32

32

32

32

32

32

32

0

1

.

.

.

15

16

17

18

19

20

21

32:1

Multiplexer

BusMux

BusMuxOut

32

Figure 3: A typical Bus

Memory Data Register: The Memory Data Register (MDR) is different from the other registers in the sense that it has two input sources and two output sinks.  Figure 4 presents how MDR is connected to the memory bus, and to the internal bus. The inputs to the MDR comes from the memory unit (Mdatain) or from the Bus (BusMuxOut).  Data is stored in the MDR using the synchronous Clock signal and the MDRin control signal.  The MDR contents can be written into the memory chip or drive the Bus.

Clear

Clock

MDRin

BusMuxOut Mdatain

(from Bus)        (from memory chip)

32

0

MDMux

32

clr

clk

write/enable

input D

MDR

output Q

32

To: BusMuxIn-MDR, or

to memory chip

Figure 4: The MDR unit

2.2 Control Unit: The Control unit is to be designed in Phase 3.  However, a block diagram is provided in Figure 5 for a better understanding of the Datapath.  The Control Unit is at the heart of the processor.   It accepts as inputs those signals that are needed to operate the processor and provides as outputs all the control signals necessary to execute the instructions.   The outputs from the Control Unit are the control signals that we use to generate Control Sequences for the instructions of the Mini SRC.

Please note that you should not be concerned about the instruction decoding in Phase 1 or Phase 2 of this project.  Instruction decoding will be done in Phase3 with VHDL or Verilog.  The details of the Control Unit will be discussed in Phase 3.


In.Portout Read Write Other inputs and control signals



Control Unit

PCout Zhighout HIout Rin Gra Grc

MDRout Zlowout LOout Rout Grb

Figure 5: Block diagram of the Control Unit

3. Lab Procedure

Design the datapath shown in Figure 1 (except for the “Select and Encode Logic”, “CON FF Logic”, “Memory chip in the Memory Subsystem”, and Input/Output ports” units) using an all HDL (VHDL or Verilog) or a mixed schematic/HDL in Quartus II design software. You are advised to follow the general steps below when designing your datapath:

1.   Design the registers R0 to R15, PC, IR, Y, Z, MAR, HI, and LO (see Figures 1 and 2).

2.   Design the bidirectional Bus (Figure 3) and connect the registers that you designed in Step 1 to the Bus.

3.   Design the MDR unit (Figure 4) and connect it to the BUS.  Leave the rest of the Memory Subsystem (connection to the memory chip) for Phase 2.

4.   Design your ALU.  Start with simple ALU operations such as logical AND, etc.  Then, design the more involved operations such as ADD/SUB, MUL, and DIV circuitry.   Finally, design the rest of the ALU operations.

•   For the multiplication unit, you are to design your own 32x32 Booth algorithm with bit-pair recoding of multiplier.

•   You are welcome to design and simulate any other advanced design techniques that you learned in class for a bonus mark.

You are advised to functionally simulate your design as you go through different design steps.   In order to test the Datapath by Functional Simulation, the following control and output signals may be required.  In  Phase 3, these control signals will be generated by the Control Unit.

Control Signals: R0in, R0out; R1in, R1out; …; R15in, R15out; HIin; HIout; LOin; LOout; PCin, PCout; IRin; Zin; Zhighout, Zlowout; Yin; MARin; MDRin, MDRout; Read; Mdatain[31..0]

Outputs: R0, R1, …, R15, HI, LO, IR, BusMuxOut, Z (minimum required output signals for demo to TA in lab), and any other outputs you may wish to observe or show in your simulation.

Using the following control sequences, test your design for and, or, add, sub, mul, div, shr, shra, shl, ror, rol, neg, and not instructions.