RISC-V Step 5: First Datapath
advanced · riscv · 400 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 5: First Datapath
Time to connect the parts into a CPU, `rv_cpu`. In this step it runs the **computational instructions**:
| Group | Instructions | Result written to `rd` |
|-------|--------------|------------------------|
| OP (0110011) | ADD SUB SLL SLT SLTU XOR SRL SRA OR AND | `alu(x[rs1], x[rs2])`, op = `{funct7[5], funct3}` |
| OP-IMM (0010011) | ADDI SLTI SLTIU XORI ORI ANDI SLLI SRLI SRAI | `alu(x[rs1], imm)` |
| LUI (0110111) | `lui rd, imm` | `imm` (the U-type immediate) |
| AUIPC (0010111) | `auipc rd, imm` | `pc + imm` (pc of this instruction) |
Every instruction here writes a register and goes to `pc + 4`; there are no branches yet, so tests are straight-line programs.
**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.
**Watch out for OP-IMM:** `funct7` is not an opcode field there; for ADDI, `instr[31:25]` is part of the immediate. Only the shifts use
`instr[30]`, to tell SRAI from SRLI. Use `{instr[30], funct3}` for OP but only for SRAI/SRLI in OP-IMM.
Your starter already contains your ALU, register file and immediate generator from steps 1–3 (or stubs, if you haven't solved them yet).
Constraints
- One instruction per clock cycle.
- wb_en and dmem_we are 0 while rst is high.
- x0 stays 0 (the register file handles it).
- Only these modules are graded: rv_alu, rv_regfile, rv_immgen, rv_cpu.
Examples
Input: addi x1, x0, 100
Output: wb_en=1, wb_rd=1, wb_data=100
x1 = 100
Input: addi x3, x0, -1024
Output: x3 = 0xFFFFFC00
Not SUB: instr[30] is an immediate bit here
Input: lui x5, 0x12345
Output: x5 = 0x12345000
U-type immediate
Input: auipc x6, 1 at pc 0x40
Output: x6 = 0x1040
pc + (1 << 12)
Common questions
- What does the RISC-V Step 5: First Datapath problem ask you to build?
- RISC-V Step 5: First Datapath Time to connect the parts into a CPU, `rv_cpu`. In this step it runs the **computational instructions**: | Group | Instructions | Result written to `rd` | |-------|--------------|------------------------| | OP (0110011) | ADD SUB SLL SLT SLTU XOR SRL SRA OR AND | `alu(x…
- What constraints does RISC-V Step 5: First Datapath have?
- One instruction per clock cycle.; wb_en and dmem_we are 0 while rst is high.; x0 stays 0 (the register file handles it).; Only these modules are graded: rv_alu, rv_regfile, rv_immgen, rv_cpu.
- What is an example input and output for RISC-V Step 5: First Datapath?
- Input addi x1, x0, 100 gives output wb_en=1, wb_rd=1, wb_data=100. x1 = 100
- Which Verilog concepts does RISC-V Step 5: First Datapath practise?
- riscv, risc-v, cpu, datapath, single-cycle.