RISC-V Step 6: Complete CPU
advanced · riscv · 600 XP
Sign in to write your solution, run it in the simulator and submit it for grading.
Sign in or create a free account →Problem
RISC-V Step 6: Complete CPU
Finish the processor: add **memory, branches and jumps** to your `rv_cpu`. When this passes, your CPU runs real programs: loops, arrays,
function calls and returns.
| Group | Instructions | Does |
|-------|--------------|------|
| LOAD (0000011) | `lw rd, imm(rs1)` | `x[rd] = mem[x[rs1] + imm]` |
| STORE (0100011) | `sw rs2, imm(rs1)` | `mem[x[rs1] + imm] = x[rs2]` |
| BRANCH (1100011) | BEQ BNE BLT BGE BLTU BGEU | if `take`: `pc = pc + imm`, else `pc + 4` |
| JAL (1101111) | `jal rd, imm` | `x[rd] = pc + 4; pc = pc + imm` |
| JALR (1100111) | `jalr rd, rs1, imm` | `x[rd] = pc + 4; pc = (x[rs1] + imm)` with bit 0 cleared |
…plus everything from step 5. Only whole-word loads and stores (`lw`/`sw`) are used; addresses are multiples of 4.
Stores and branches don't write a register (`wb_en = 0`). Branch and JAL offsets are relative to the **current** instruction's PC.
**Interface** (the same for steps 5 and 6)
| Port | Dir | Width | Meaning |
|------|-----|-------|---------|
| `clk`, `rst` | in | 1 | Clock; synchronous active-high reset (PC = 0) |
| `imem_addr` | out | 32 | Address of the instruction to execute (the PC) |
| `imem_data` | in | 32 | That instruction; instruction memory reads combinationally |
| `dmem_addr`, `dmem_wdata`, `dmem_we` | out | 32, 32, 1 | Data memory: byte address, store data, store enable |
| `dmem_rdata` | in | 32 | Data memory read data at `dmem_addr` (combinational) |
| `wb_en`, `wb_rd`, `wb_data` | out | 1, 5, 32 | Register write-back: 1 when this instruction writes `x[wb_rd] = wb_data` |
The memories live in the testbench. The write-back port is how the tests see your results: they watch every register write.
Drive your register file's write port from `wb_en`, `wb_rd` and `wb_data` so the two always agree.
**Single-cycle:** each rising edge of `clk` finishes one instruction: registers and memory are written and the PC moves on.
**While `rst` is high:** `wb_en` and `dmem_we` must be 0 and the PC goes to 0.
`dmem_addr`/`dmem_wdata` only matter while loading or storing, and `wb_rd`/`wb_data` only while `wb_en` is 1.
The hidden tests run complete programs: a summing loop, an array scan with loads and stores, function calls with `jal`/`jalr`,
and every branch condition, checking all 32 registers and the whole data memory at the end.
Your starter already contains your step-5 CPU and your branch comparator (or stubs). Extend `rv_cpu` there.
Constraints
- One instruction per clock cycle.
- wb_en and dmem_we are 0 while rst is high.
- JALR clears bit 0 of the target.
- Loads and stores use x[rs1] + imm as the byte address.
Examples
Input: sw x1, 0x100(x0)
Output: dmem_we=1, dmem_addr=0x100, dmem_wdata=x1
Store
Input: bne x2, x3, -8 with x2 != x3
Output: pc = pc - 8
Taken branch, backwards
Input: jal x1, func
Output: x1 = pc + 4; pc = func
Call
Input: jalr x0, x1, 0
Output: pc = x1
Return
Common questions
- What does the RISC-V Step 6: Complete CPU problem ask you to build?
- RISC-V Step 6: Complete CPU Finish the processor: add **memory, branches and jumps** to your `rv_cpu`. When this passes, your CPU runs real programs: loops, arrays, function calls and returns.
- What constraints does RISC-V Step 6: Complete CPU have?
- One instruction per clock cycle.; wb_en and dmem_we are 0 while rst is high.; JALR clears bit 0 of the target.; Loads and stores use x[rs1] + imm as the byte address.
- What is an example input and output for RISC-V Step 6: Complete CPU?
- Input sw x1, 0x100(x0) gives output dmem_we=1, dmem_addr=0x100, dmem_wdata=x1. Store
- Which Verilog concepts does RISC-V Step 6: Complete CPU practise?
- riscv, risc-v, cpu, single-cycle, capstone.