Lab 4: TinyRV1 Processor
Part B: TinyRV1 Processor
Lab 4 will give you experience designing, implementing, testing, and prototyping a single-cycle processor microarchitecture and a specialized accelerator. The processor will implement the TinyRV1 instruction set. The instruction set manual is located here:
The lab will continue to leverage concepts from Topic 2: Combinational Logic, Topic 3: Boolean Algebra, Topic 4: Combinational Building Blocks, Topic 6: Sequential Logic, Topic 7: Finite-State Machines, and Topic 8: Sequential Building Blocks. The lab will also leverage concepts from Topic 9: Instruction Set Architecture and Topic 10: Single-Cycle Processors The lab will continue to provide opportunities to leverage the three key abstraction principles: modularity, hierarchy, and regularity. The lab includes seven parts:
-
Part A: Processor Components
- Due 11/5 @ 11:59pm via GitHub
- Students should work on Part A before, during, and after your assigned lab section during the week of 11/2
- Pre-lab survey on Canvas is (roughly) due by end of lab section during the week of 11/2
-
Part B: TinyRV1 Processor
- Due 11/12 @ 11:59pm via GitHub
- Students should work on Part B before, during, and after your assigned lab section during the week of 11/9
-
Part C: Accumulate Accelerator
- Due 11/24 @ 11:59pm via GitHub
- Students should plan to submit Part C before they leave for Thanksgiving Break
-
Part D: FPGA Prototype v1
- Due week of 11/16 during assigned lab section
- This part will focus on prototyping the code developed in Part A+B
- Even though completed with a partner, every student must turn in their own paper check-off sheet in their lab section!
-
Part E: FPGA Prototype v2
- Due week of 11/30 during assigned lab section
- This part will focus on prototyping the code developed in Part A+B+C
- Even though completed with a partner, every student must turn in their own paper check-off sheet in their lab section!
-
Part F: TinyRV1 Assembly
- Due 12/3 @ 11:59pm via GitHub
- This part will include all of the assembly developed during Part D+E
-
Part G: Datasheet and Report
- Due on 12/8 at 11:59pm for all groups!
- Post-lab survey on Canvas is due at the same time as the report
All parts of Lab 4 must be done with a partner. You can confirm your partner on Canvas (Click on People, then Groups, then search for your name to find your lab group).
Both students must contribute to all parts!
It is not acceptable for one student to exclusively work on the code while the other student exclusively works on the report. It is not acceptable for one student to exclusively work on hardware design while the other student exclusively works on testing. Both students must contribute to all parts. Student understanding of Verilog design and testing will be assessed on the prelim exams, final exam, and Verilog coding exam. The instructors will also survey the Git commit log on GitHub to confirm that both students are contributing equally. If you are using pair programming, then both students must take turns using their own account so both students have representative Git commits. Students should create commits after finishing each step of the lab, so their contribution is clear in the Git commit log. A student's whose contribution is limited as represented by the Git commit log will receive a significant deduction to their lab score.
This handout assumes that you have read and understand the course tutorials and that you have attended the discussion sections. This handout assumed you have successfully completed Part A. You should have already cloned your group remote repository, so use git pull to ensure you have any recent updates before working on your lab assignment.
where XX should be replaced with your group number.
The following table shows all of the hardware modules you will be developing in Lab 4.

1. Interface and Implementation Specification
A complete TinyRV1 embedded system includes the following key components: (1) the TinyRV1 processor itself; (2) 512 bytes of physical memory for storing instructions and data; (3) an SPI unit to enable a host workstation to write assembly programs into physical memory; (4) various external I/O devices (e.g., switches, sevent-segment displays, distance sensor, multi-note player); and (5) a memory bus which interconnects the processor, physical memory, SPI, and external I/O devices.

Notice the go signal which is connected to the instruction and data
memory wait inputs using a NOT gate. We will initially set the go
signal to zero to force the processor to wait while we write the assembly
program into physical memory through the memory bus. Once the assembly
program has been written into physical memory, we can set the go signal
to one and the processor can stop waiting and start executing the
program.
We will provide you the physical memory module, you implemented the SPI unit in Part A, and you have already implemented various external I/O devices in previous labs. In Part B, you will be using the datapath components from Part A along with components from previous labs to implement the TinyRV1 processor and memory bus.
1.1. TinyRV1 Single-Cycle Processor
The single-cycle TinyRV1 processor has the following interface:
module ProcScycle
(
(* keep=1 *) input logic clk,
(* keep=1 *) input logic rst,
// Memory Interfaces
(* keep=1 *) output logic imem_val,
(* keep=1 *) input logic imem_wait,
(* keep=1 *) output logic [31:0] imem_addr,
(* keep=1 *) input logic [31:0] imem_rdata,
(* keep=1 *) output logic dmem_val,
(* keep=1 *) input logic dmem_wait,
(* keep=1 *) output logic dmem_type,
(* keep=1 *) output logic [31:0] dmem_addr,
(* keep=1 *) output logic [31:0] dmem_wdata,
(* keep=1 *) input logic [31:0] dmem_rdata,
// Trace Interface
(* keep=1 *) output logic trace_val,
(* keep=1 *) output logic [31:0] trace_pc,
(* keep=1 *) output logic trace_wen,
(* keep=1 *) output logic [4:0] trace_wreg,
(* keep=1 *) output logic [31:0] trace_wdata
);
Memory Interfaces
The instruction memory interface is used to read instructions similar
to how we read notes in Lab 3. To read an instruction set the imem_val
output port high and the imem_addr output port to the desired
instruction address; the instruction will be returned via the
imem_rdata input port combinationally (i.e., in the same cycle). The
data memory interface enables load and store instructions to read and
write memory. It is similar to the instruction memory interface except
now we have an additional dmem_type output port which specifies whether
we want to read memory (i.e., dmem_type is zero) or write memory (i.e.,
dmem_type is one). We also need the dmem_wdata output port for the
write data. Finally, both the instruction and data memory interfaces
include a wait input which enables the memory to tell the processor to
wait and try the memory request again on the next cycle.
Trace Interface
The trace interface is used for verification and should produce a "trace" of all instructions executed by the processor. This interface was not discussed in lecture, but is an important practical aspect of implementing a real processor. We need a simple way to check that each instruction has executed correctly.
Whenever the processor executes an instruction it should set the
trace_val output high. It should also set the trace_pc output port to
the PC of the executed instruction. If the instruction writes the
register file, it should set trace_wen to one, trace_wreg to the
corresponding write destination register, and trace_data to the data
written to the register file. If the instruction writes x0 then
trace_wen should be one, trace_wreg should be zero, and trace_data
is undefined. We will be able to write test cases that check the trace
interface to verify the processor is executing a given assembly program
correctly.
Initial Implementation
The TinyRV1 single-cycle processor implementation will be decomposed into
a datapath and a control unit. The datapath must be implemented
structurally meaning we should only instantiate other components without
using any always blocks or combinational logic. The control unit will be
implemented using a single casez in an always_comb block along with
assign statements. We give you an initial processor implementation that
supports the ADDI and ADD instruction but does not support the memory
wait signals. The datapath and control unit for this initial processor
are shown below.

The control signal table for this initial processor is shown below.
// Task for setting control signals
task automatic cs
(
input logic op2_sel_
);
op2_sel = op2_sel_;
endtask
// Control signal table
always_comb begin
casez ( inst )
// op2
// sel
`TINYRV1_INST_ADDI: cs( 1 );
`TINYRV1_INST_ADD: cs( 0 );
default: cs( 'x );
endcase
end
A control signal table has a column for every control signal and a row
for every instruction. Since the initial implementation only supports two
instructions, the initial control signal table only has two rows. The
first row has all of the control signals required to execute the ADDI
instruction, and the second row has all of the control signals required
to execute the ADD instruction. We are using a casez because we want to
support don't cares in the instruction decoding (i.e., see
TINYRV1_INST_ADDI in tinyrv1.v). In this case, we only need one
column since we currently only have a single control signal: op2_sel
which controls the mux for operand 2 of the ALU. Notice how we are using
a SystemVerilog task named cs (for control signals) to set the control
signals. This will make it easy to add more columns in a clean way. You
can use localparams to create control signal labels (i.e., rf, imm)
if you like, but it is not required.
The following code will connect the initial control unit up to the initial datapath.
// Control Signals (Control Unit -> Datapath)
logic op2_sel;
// Status Signals (Datapath -> Control Unit)
logic [31:0] inst;
// Instantiate/Connect Datapath
ProcScycleDpath dpath
(
.clk (clk),
.rst (rst),
.imem_addr (imem_addr),
.imem_rdata (imem_rdata),
.dmem_addr (dmem_addr),
.dmem_wdata (dmem_wdata),
.dmem_rdata (dmem_rdata),
.trace_pc (trace_pc),
.trace_wen (trace_wen),
.trace_wreg (trace_wreg),
.trace_wdata (trace_wdata),
.op2_sel (op2_sel),
.inst (inst)
);
// Instantiate/Connect Control
ProcScycleCtrl ctrl
(
.rst (rst),
.imem_val (imem_val),
.imem_wait (imem_wait),
.dmem_val (dmem_val ),
.dmem_wait (dmem_wait),
.dmem_type (dmem_type),
.trace_val (trace_val),
.op2_sel (op2_sel),
.inst (inst)
);
There are two things to notice: (1) connecting all of these ports is
quite tedious; and (2) every port connects to a signal with the exact
same name. Take a quick look at the code in ProcScycle which actually
connects the datapath to the control unit.
// Control Signals (Control Unit -> Datapath)
logic op2_sel;
// Status Signals (Datapath -> Control Unit)
logic [31:0] inst;
// Insantiate/Connect Datapath and Control Unit
ProcScycleDpath dpath
(
.*
);
ProcScycleCtrl ctrl
(
.*
);
Notice how much more compact this is! We are using the SystemVerilog .*
operator which connects every port to a signal with the exact same name.
This way whenever we want to add a new control or status signal all we
need to do is declare a signal with the right name and we are done.
This initial implementation does not handle the memory wait signals and indeed we recommend finishing all eight instructions (including thorough testing!) without memory waits before incorporating this support into your processor.
Final Implementation
The final datapath and control unit are shown below.

This is the same as in lecture except with the trace interface.
The final control signal table will have eight columns and eight rows just like in lecture. This is an example of what the first two rows might look like, but keep in mind that your implementation might look different depending on how you implement your datapath.
task automatic cs
(
input logic [1:0] pc_sel_,
input logic [1:0] imm_type_,
input logic op2_sel_,
input logic alu_func_,
input logic [1:0] wb_sel_,
input logic rf_wen_pre_,
input logic dmem_val_pre_,
input logic dmem_type_
);
pc_sel = pc_sel_;
imm_type = imm_type_;
op2_sel = op2_sel_;
alu_func = alu_func_;
wb_sel = wb_sel_;
rf_wen_pre = rf_wen_pre_;
dmem_val_pre = dmem_val_pre_;
dmem_type = dmem_type_;
endtask
// Control signal table
always_comb begin
casez ( inst )
// pc imm op2 alu wb rf dmem dmem
// sel type sel func sel wen val type
`TINYRV1_INST_ADDI: cs( 0, 0, 1, 0, 1, 1, 0, 'x );
`TINYRV1_INST_ADD: cs( 0, 'x, 0, 0, 1, 1, 0, 'x );
...
default: cs( 'x, 'x, 'x, 'x, 'x, 'x, 'x, 'x );
endcase
end
Again, we are using a SystemVerilog task named cs to enable cleanly
setting eight signals in one line of the casez. Feel free to use
localparams for some of the control signal labels (e.g., I, imm,
rf, add, alu, etc).
Integrating the Memory Wait Signals
Once you have all eight instructions thoroughly tested without any memory
waits, you can try to incorporate the imem_wait and dmem_wait
signals. The first step is to add a new pc_en control signal that is
connected to the enable input of the PC. Then make sure the PC is not
enabled if we are waiting on memory.
We also need to make sure we do not write garbage data to the register
file if we are waiting on either the instruction memory or the data
memory. This is why the control signal table writes a "preliminary"
version of the rf_wen control signal; we use the _pre suffix to
indicate it is a preliminary version. We will need to add some additional
logic (in an assign statement after the always_comb) to incorporate
the memory wait signals. If either imem_wait or dmem_wait are one we
need to ensure that rf_wen is zero so we do not accidently write
garbage to a register in the register file; if both imem_wait and
dmem_wait are zero then rf_wen is the same as the preliminary
version. So for example, the additional combinational logic for rf_wen
to factor in the memory wait signals might look like this:
So rf_wen is one if: we are not in reset and we are not waiting on
the instruction memory and we are not waiting on the data memory and
the current instruction really does want to write the register file.
Finally, we need to make sure we do not write garbage data to memory if
we are waiting on the instruction memory. Again, this is why the control
signal table writes a "preliminary" version of dmem_val. We can then
combine the imem_wait signal and dmem_val_pre to determine
dmem_val. Do not make dmem_val depend on dmem_wait since this
could cause a combinational loop!
Use an incremental design approach!
Do not use a big bang design approach! See Section 4 to learn more about the suggested incremental design approach.
1.2. Memory Bus
The memory bus interconnects the host memory interface (hmem), processor's instruction memory interface (imem), processor's data memory interface (dmem), physical memory port 0 (mem0), physical memory port 1 (mem1), and external I/O devices. The interface for the memory bus is shown below.

The memory bus needs to implement the following specification:
- The hmem and imem interfaces both use the mem0 interface to access physical memory
- If both hmem and imem have valid requests, then the hmem interface has higher priority
- The hmem interface can only perform writes, and the imem interface can only perform reads
- Only the dmem interface can use the mem1 interface to access physical memory
- Only the dmem interface can read the external I/O inputs which are memory mapped to addresses 512-524 (0x200-0x20c)
- Only the dmem interface can write the external I/O outputs which are memory mapped to addresses 528-540 (0x210-0x21c)
- Writing an external I/O input interface is undefined
- Reading an external I/O output interface is undefined
- A dmem request which reads or writes external I/O should not result in a request to physical memory on the mem1 interface
The following datapath implements this specification.

Notice how the datapath has two distinct parts. The left-hand side of the datapath interconnects the hmem, imem, and mem0 interfaces while the right-hand side of the datapath interconnects the dmem, mem1, and external I/O interfaces.
The address decoder takes as input the dmem address and outputs whether the address maps to physical memory or one of the memory mapped external I/Os. It should produces nine single bit outputs:
sel_memshould be one if address is 0-512 (0x000-0x200)sel_in0should be one if address is 512 (0x200)sel_in1should be one if address is 516 (0x204)sel_in2should be one if address is 520 (0x208)sel_in3should be one if address is 524 (0x20c)sel_out0should be one if address is 528 (0x210)sel_out1should be one if address is 532 (0x214)sel_out2should be one if address is 536 (0x218)sel_out3should be one if address is 540 (0x21c)
You should implement this module using assign statements.
The read data mux takes as input the read data from physical memory, the
four memory mapped external inputs, and the sel_mem, sel_in0,
sel_in1, sel_in2, and sel_in2 signals from the address decoder. The
read data mux uses the select signals from the address decoder to choose
which data to output as the dmem read data. If sel_mem is one, the read
data mux should choose the read data from physical memory. If in0_sel
is one, the read data mux should choose memory mapped external input in0,
if in1_sel is one, the read data mux should choose memory mapped
external input in1, and so on.
The OR gate labeled A means if hmem OR imem have a valid request then we should set mem0 to be valid. The mux labeled B means that if there is a valid hmem request it takes priority over any imem request when determining the mem0 address. Notice how mem0 type is connected to the hmem valid signal so if we have a valid hmem request, we can be sure we will do a write (i.e., if hmem is valid, then mem0 type will be one which means write). If hmem is not valid, then the mem0 type will be a read.
The AND gate labeled C is used to determine when we have a valid dmem
request AND that request is a write. The output of the AND gate is
connected to four AND gates labelled D. These four AND gates each take
one of sel0_out, sel1_out, sel2_out, and sel3_out to determine
the write enable for the four output registers. This logic ensures we
only write an output register if we have a valid dmem request, that
request is a write, and the dmem address matches the corresponding memory
mapped I/O address. Finally, the AND gate labelled E is used to AND dmem
valid with sel_mem to ensure that we only make a request to mem1 if we
we have a valid dmem request AND the address is less 0-512 (0x000-0x200).
You will need to implement the address decoder in
MemoryBusAddrDecoder_RTL.v, the read data mux in
MemoryBusReadDataMux_RTL.v, and then compose these modules with a
32-bit 2-to-1 mux and some simple Boolean logic to implement the memory
bus.
2. Testing Strategy
As always, we need a compelling strategy to ensure the correctness of each component (i.e., TinyRV1 processor and memory bus), but we also need a strategy to ensure the correctness of the integration of these components.
2.1. Processor Unit Tests
Testing the processor is more complex than testing individual hardware blocks. We have provided you some testing infrastructure to simplify the process, but students should still expect to dedicate significant time to verifying their processor correctly implements the TinyRV1 ISA.
We have provided you a functional-level FL processor model (also called
an instruction set simulator) located in test/ProcFL.v. The FL
processor model executes the instruction semantics behaviorally using
high-level Verilog. It is not meant to model hardware. The FL processor
model can be used to make sure your tests are correct before you run
those tests on your single-cycle processor.
The test cases for the processor is located in these test files:
test/Proc-addi-test-cases.vtest/Proc-add-test-cases.vtest/Proc-mul-test-cases.vtest/Proc-lw-test-cases.vtest/Proc-sw-test-cases.vtest/Proc-jal-test-cases.vtest/Proc-jr-test-cases.vtest/Proc-bne-test-cases.vtest/Proc-mmio-test-cases.vtest/Proc-mix-test-cases.v
Each file should only include a single type of instruction with four exceptions:
-
You will need to use ADDI instructions in all of the test cases since this is the easiest way to initialize registers with constant data
-
You will need to use LW instructions in your SW test cases since this is the only way to ensure a SW instruction actually writes memory.
-
You will need to use LW and SW instructions (along with ADDI instructions) in your MMIO test case.
-
You will need to use all eight instructions together to write the final mix test cases.
The final mix test cases are very important! They help test that the different instructions can execute together correctly, but these test cases are also used for memory wait testing and integration testing.
You can run the test cases for the ADDI and ADD instructions on the FL processor like this:
% cd ${HOME}/ece2300/groupXX/build
% make ProcFL-addi-test && ./ProcFL-addi-test
% make ProcFL-add-test && ./ProcFL-add-test
You can run the test cases for the ADDI and ADD instructions on the single-cycle RTL processor like this:
% cd ${HOME}/ece2300/groupXX/build
% make ProcScycle-addi-test && ./ProcScycle-addi-test
% make ProcScycle-add-test && ./ProcScycle-add-test
You will need to add more tests cases to the appropriate -test-cases.v
file. Do not simple have a single directed test case (i.e., a single
task); you must have many directed test cases (i.e., many tasks). Each
directed test case should focus on testing a different aspect of the
corresponding instruction. Remember to always make sure your tests pass
on the FL processor model before attempting to run those tests on your
single-cycle processor model!
2.2. Arithmetic Instructions
Processor test cases look like this:
task test_case_1_basic();
t.test_case_begin( "test_case_1_basic" );
// Write assembly program into memory
asm( 0, "addi x1, x0, 2" );
asm( 4, "addi x2, x1, 2" );
// Tell processor to start executing program
go();
// Check each executed instruction
// pc en reg data
check_trace( 0, 1, 1, 2 ); // addi x1, x0, 2
check_trace( 4, 1, 2, 4 ); // addi x2, x1, 2
t.test_case_end();
endtask
Every processor test case includes three parts.
-
asmtasks are used to write instructions into the memory. Theasmtask takes two arguments: the address for the instruction (you can use decimal or hexadecimal) and an assembly instruction represented as a string. Theasmtask will take care of assembling the assembly instruction into a machine instruction. Theasmtasks represent the static instruction sequence (i.e., what instructions are stored in memory before the processor starts executing). -
gotask is used to tell the processor to start executing the program. The go signal is set to zero during the first part which forces the processor to wait, then thegotask sets to one, and it remains one for the third part. -
check_tracetasks are like thechecktasks you have seen elsewhere, butcheck_tracetasks will wait for thetrace_valsignal to be high before checking to see if thetrace_addrandtrace_dataoutputs from the processor match the desired values. Thecheck_tracetasks are used to check the dynamic instruction sequence (i.e., what instructions the processor actually executes at runtime).
The above basic test case for the ADDI instruction uses the trace to make sure the first ADDI instruction writes the value 2 to the register file and the second ADDI instruction writes the value 4 to the register file. When writing register x0, the trace data is undefined. We do not want to enforce that the register write data is zero when writing x0 since this would require special hardware to handle this case. Here is how you might test reading and writing register x0.
task test_case_2_regX0();
t.test_case_begin( "test_case_2_regX0" );
// Write assembly program into memory
asm( 0, "addi x1, x0, 0" );
asm( 4, "addi x0, x1, 0" );
// Tell processor to start executing program
go();
// Check each executed instruction
// pc en reg data
check_trace( 0, 1, 1, 0 ); // addi x1, x0, 0
check_trace( 4, 1, 0, 32'h? ); // addi x0, x1, 0
t.test_case_end();
endtask
Here are some suggestions for what to test for arithmetic instructions:
- Test reading and writing register x0
- Test reading and writing registers x1-x31
- Test reading and writing a single register
- Test instruction sequences with register dependencies
- Test positive values
- Test negative values
- Test overflow
"Reading and writing a single register" means using the same register for the inputs and outputs of a single instruction. "Register dependencies" means an instruction sequence where one instruction writes a register and the next instruction reads that same register (e.g., an ADDI writes x1 and then an ADDI reads x1).
2.3. Memory Instructions
Processor test cases for memory can include an additional part:
task test_case_1_basic();
t.test_case_begin( "test_case_1_basic" );
// Write assembly program into memory
asm( 0, "addi x1, x0, 256" );
asm( 4, "lw x2, 0(x1)" );
// Write data into memory
data( 256, 32'hdead_beef );
// Tell processor to start executing program
go();
// Check each executed instruction
// pc en reg data
check_trace( 0, 1, 1, 256 ); // addi x1, x0, 256
check_trace( 4, 1, 2, 32'hdead_beef ); // lw x2, 0(x1)
t.test_case_end();
endtask
In addition to the asm tasks and check_trace tasks, we can also use a
data task to write data into the memory. The above basic test case for
the LW instruction first uses an ADDI instruction to get the memory
address 256 into register x1. The test case then performs a LW
instruction to load the data from address 256 into register x2. The
check_trace tasks verify that the ADDI instruction correctly writes the
address to the register file, and that the LW instruction correctly loads
the value 0xdeadbeef from memory address 256.
Here are some suggestions for what to test for memory instructions:
- Test reading and writing register x0
- Test reading and writing registers x1-x31
- Test reading and writing a single register
- Test instruction sequences with register dependencies
- Test positive offsets
- Test negative offsets
"Reading and writing a single register" means using the same register for the LW base address as what is used for the LW destination. "Register dependencies" means an instruction sequence where one instruction writes a register and the next instruction reads that same register (e.g., a LW writes x1 and then an ADDI reads x1).
2.4. Control Flow Instructions
The check_trace tasks become particularly important when testing
control flow instructions. The following test case is for the JAL
instruction:
task test_case_1_basic();
t.test_case_begin( "test_case_1_basic" );
// Write assembly program into memory
asm( 0, "addi x1, x0, 1" );
asm( 4, "jal x2, 12" );
asm( 8, "addi x1, x0, 2" );
asm( 12, "addi x1, x0, 3" );
// Tell processor to start executing program
go();
// Check each executed instruction
// pc en reg data
check_trace( 0, 1, 1, 1 ); // addi x1, x0, 1
check_trace( 4, 1, 2, 8 ); // jal x2, 12
check_trace( 12, 1, 1, 3 ); // addi x1, x0, 3
t.test_case_end();
endtask
Here we can see the static instruction sequence includes four instructions, but the dynamic instruction sequence only includes three instructions because the JAL instruction jumps over the instruction at address 12. Note that in the assembly format used for testing our processor, the literal in a JAL and BNE instruction is the absolute address of the target not the actual immediate. The assembler will take care of creating the appropriate PC relative immediate.
Here are some suggestions for what to test for control flow instructions:
- Test reading and writing register x0
- Test reading and writing registers x1-x31
- Test reading a single register
- Test instruction sequences with register dependencies
- Test chain of control flow instructions (e.g., JAL to a JAL to a JAL)
- Test forward control flow (e.g. JAL jumps to higher address)
- Test backward control flow (e.g. JAL jumps to lower address)
- Test loops (e.g. use BNE to implement loop)
- Test loop to self (e.g., JAL jumps to itself)
"Reading and writing a single register" means using the same register for both inputs of a BNE. "Register dependencies" means an instruction sequence where one instruction writes a register and the next instruction reads that same register (e.g., a JAL writes x1 and then an ADDI reads x1).
2.5. Memory Mapped I/O
You will need to write one or more directed test cases for memory mapped
I/O in Proc-mmio-test-cases.v. These test cases will need to use two
new tasks: set_inputs and check_outputs. Here is what the basic MMIO
test case looks like:
task test_case_1_basic();
t.test_case_begin( "test_case_1_basic" );
// Write assembly program into memory
asm( 0, "addi x1, x0, 512" ); // MMIO in0
asm( 4, "addi x2, x0, 528" ); // MMIO out0
asm( 8, "lw x3, 0(x1)" ); // x2 = in0
asm( 12, "sw x3, 0(x2)" ); // out0 = x2
// Set MMIO inputs (takes one cycle to see these values in processor!)
set_inputs( 1, 0, 0, 0 );
// Tell processor to start executing program
go();
// Check each executed instruction
// pc en reg data
check_trace( 0, 1, 1, 512 ); // addi x1, x0, 512
check_trace( 4, 1, 2, 528 ); // addi x5, x0, 528
check_trace( 8, 1, 3, 1 ); // lw x2, 0(x1) <- in0
check_trace( 12, 0, 0, 32'h? ); // sw x2, 0(x5) -> out0
// Check MMIO outputs
check_outputs( 1, 0, 0, 0 );
t.test_case_end();
endtask
This test case:
- Writes the assembly program into memory
- Sets the MMIO inputs
- Tells the processor to go
- Reads an MMIO input using a LW instruction from address 512 (0x200)
- Writes an MMIO input using a SW instruction to address 528 (0x210)
- Checks the MMIO outputs
You should write at least one more directed test case that reads all four
MMIO inputs and writes all four MMIO outputs. You can also check the
outputs and change the inputs in the middle of executing your assembly
program by simply interleaving check_trace with set_inputs and
check_outputs.
Note it takes one instruction for the effects of the set_inputs task
to be visible to the processor! So you cannot use set_inputs and then
immediately use a LW instruction to read a MMIO input. You would need to
use set_inputs, execute some other instruction, and then you can use a
LW instruction to read the MMIO input.
2.6. Memory Wait
As mentioned earlier, the mix tests are also used test if your processor
correctly handles the memory wait signals. Take a look in
ProcScycle-wait-test.v and notice that the asm task now takes a
cycle, and the go task now actually toggles the go signals.
task asm
(
input logic [31:0] addr,
input string str
);
mem.write( addr, tinyrv1.asm( addr, str ) );
#8;
`ECE2300_CHECK_EQ_HEX( imem_addr, 32'h0 );
`ECE2300_CHECK_EQ( trace_val, 1'b0 );
#2;
endtask
...
always_ff @( posedge clk ) begin
if ( rst )
go_ <= 1'b0;
else if ( go_req )
go_ <= 1'b1;
end
task go();
go_req = 1'b1;
#10;
go_req = 1'b0;
endtask
So the wait test will reuse the mix test but now forces the processor to wait while writing the assembly program into physical memory. This will help catch issues if the processor is not waiting correctly.
2.7. Memory Bus Unit Tests
We provide you unit tests for the memory bus address decoder, memory bus read data mux, and the memory bus. Feel free to write more if you like, but it is not required.
2.8. Integration Tests
We now have rigorously unit tested your single-cycle processor in isolation along with the memory bus, so the next step is integration testing. There are three kinds of integration testing:
-
Processor+Bus Testing: We provide a
ProcScycle-bus-test.vtest bench which reuses your mix test cases to test the integration of the processor and the memory bus. It is critical that your mix test cases are comprehensive to ensure that our integration testing is also comprehensive! -
Processor+Bus+MMIO Testing: We provide you a
ProcScycle-bus-mmio-test.vtest bench which executes your MMIO test cases to test the integration of the processor, memory bus, and MMIO. Be sure to run your MMIO tests on the FL processor first! -
Processor+Bus+SPI Testing: We provide a
ProcScycle-bus-spi-test.vtest bench which reuses your mix test cases to test the integration of the processor and the memory bus. It is critical that your mix test cases are comprehensive to ensure that our integration testing is also comprehensive! Try looking at the waveforms from one of your test cases so you can confirm the SPI transsactions are being used to write the assembly program into physical memory through the hmem interface.
4. Incremental Design Approach
Implementing the processor system is the culmination of many months of
work on the lab assignments. It is a complex hardware system so we
strongly discourage using a big bang design approach. Do not just
start writing code, try to implement the entire datapath and control unit
in one shot, and then see if you can get it to work. Do not implement
the processor and memory bus and then start testing. This approach can
easily take hours and hours. You can implement and test the processor in
parallel with implementing and testing the memory bus. Once both the
processor and memory bus have been unit tested, then you can use the
integration tests (i.e., ProcScycle-bus-test.v,
ProcScycle-bus-mmio-test.v, ProcScycle-bus-spi-test.v).
When implementing the processor, your goal is to incrementally modify the datapath and control unit to add support for each of the remaining six instructions (i.e., MUL, LW, SW, JAL, JR, BNE) one at a time. Start by ignoring the memory wait signals, and add support for these signals at the very end once all eight instructions have been fully implemented and tested. Adding each instruction should involve the following eight steps:
- Step 1: Write at least one directed test case for the instruction (
Proc-*-test-cases.v) - Step 2: Modify the datapath (
ProcScycleDpath.v) - Step 3: Add ports to the datapath for new control/status signals (
ProcScycleDpath.v) - Step 4: Add ports to the control unit for new control/status signals (
ProcScycleCtrl.v) - Step 5: Modify the control signal table by adding a new column
for each new control signal and a new row for the new
instruction (
ProcScycleCtrl.v) - Step 6: Fill in the control signal table, use
`xfor don't cares (ProcScycleCtrl.v) - Step 7: Add wires between the new datapath and control unit ports (
ProcScycle.v) - Step 8: Write more directed test cases to test the
instruction (
Proc-*-test-cases.v)
Use this eight step process. Implement one instruction, thoroughly test that instruction, then move on to the next instruction. Once you have finished implementing all eight instructions and thoroughly tested each one, then you can work on adding support for the memory wait signals.
Let's illustrate this process by adding the MUL instruction. First, we
need to write a simple directed test case (Step 1). We might write a
directed test case that tests multiplying small numbers together. Then we
need to modify the datapath in ProcScycleDpath.v to include a
multiplier and a new write-back multiplexor which will choose whether the
ALU or the multiplier writes the register file (Step 2). Here is the
modified datapath.

Notice this means we have a new control signal wb_sel. So we need to
add a new one-bit input port to ProcScycleDpath.v named wb_sel (Step
3). We also need to add a new one-bit output port to ProcScycleCtrl.v
named wb_sel (Step 4). In the control unit, we need to add a new column
and a new row to the control signal table (Step 5) like this:
// Task for setting control signals
task automatic cs
(
input logic op2_sel_,
input logic wb_sel_
);
op2_sel = op2_sel_;
wb_sel = wb_sel_;
endtask
// Control signal table
always_comb begin
casez ( inst )
// op2 wb
// sel sel
`TINYRV1_INST_ADDI: cs( 1, TODO );
`TINYRV1_INST_ADD: cs( 0, TODO );
`TINYRV1_INST_MUL: cs( TODO, TODO );
default: cs( 'x, 'x );
endcase
end
Notice how adding a new column to the control signal table also requires
modifying the cs task. Now we need to fill in the TODO entries with
the correct values, using `x if we don't care (Step 6). We need to add
a new wb_sel wire to connect these new wb_sel port in the datapath to
the new wb_sel port in the control unit (Step 7):

Here is how we can add this connection in ProcScycle.v:
// Control Signals (Control Unit -> Datapath)
logic op2_sel;
logic wb_sel;
// Status Signals (Datapath -> Control Unit)
logic [31:0] inst;
// Insantiate/Connect Datapath and Control Unit
ProcSycleDpath dpath
(
.*
);
ProcScycleeCtrl ctrl
(
.*
);
The .* makes these top-level connections very simple! Finally, we
must thoroughly test this instruction before moving on to the next
instruction (Step 8).
5. Lab Code Submission
To submit your code you simply push your code to GitHub. You can push
your code as many times as you like before the deadline. Students are
responsible for going to the GitHub website for your repository, browsing
the source code, and confirming the code on GitHub is the code they want
to submit is on GitHub Be sure to verify your code is passing your tests
both on ecelinux and on GitHub Actions. Your design code will be
assessed both in terms of code quality, verification quality, and
functionality.
5.1. Code Quality
Your code quality score will be based on how well you follow the course coding conventions posted here:
Code quality for Part B will be assessed after the Part C deadline.
5.2. Verification Quality
Verification quality is based on how well your testing enables making a compelling case for correctness. You will need to write compelling directed test cases for your processor. Use comments appropriately to describe your test cases.
5.3. Functionality
Your functionality score will be determined by running your code against a series of tests developed by the instructors to test its correctness. Note that we will be using the automated build system to test your final code submission as shown below.