RISC-V Step 2: Register File
advanced · riscv · 220 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 2: Register File
RV32I has 32 general-purpose registers, `x0` to `x31`, each 32 bits. An instruction like `add x3, x1, x2` reads two registers and writes
one, so the register file has **two read ports and one write port**.
**Interface**
| Port | Dir | Width | Meaning |
|------|-----|-------|---------|
| `clk` | in | 1 | Clock |
| `we` | in | 1 | Write enable |
| `rs1`, `rs2` | in | 5 | Registers to read |
| `rd` | in | 5 | Register to write |
| `wd` | in | 32 | Value to write |
| `rd1`, `rd2` | out | 32 | Values of `x[rs1]` and `x[rs2]` |
**Behaviour**
- **Reads are combinational:** `rd1`/`rd2` follow `rs1`/`rs2` immediately, with no clock.
- **Writes happen on the rising edge of `clk`** when `we` is 1: `x[rd] <= wd`. A write is visible on the read ports right after that edge.
- **`x0` is hardwired to zero:** writes to it are ignored and it always reads 0. Programs rely on this: `addi x1, x0, 5` means "x1 = 5".
Registers other than `x0` start undefined, like real hardware; the tests write a register before reading it.
Constraints
- Two combinational read ports, one synchronous write port.
- x0 always reads 0, whatever was written to it.
- No reset is needed.
Examples
Input: we=1, rd=3, wd=0xCAFE0003, rising edge
Output: x3 = 0xCAFE0003
Ordinary write
Input: we=1, rd=0, wd=0xFFFFFFFF, rising edge; then rs1=0
Output: rd1 = 0
x0 ignores writes
Input: rs1=3, rs2=3
Output: rd1 = rd2 = x3
Both ports can read the same register
Common questions
- What does the RISC-V Step 2: Register File problem ask you to build?
- RISC-V Step 2: Register File RV32I has 32 general-purpose registers, `x0` to `x31`, each 32 bits. An instruction like `add x3, x1, x2` reads two registers and writes one, so the register file has **two read ports and one write port**.
- What constraints does RISC-V Step 2: Register File have?
- Two combinational read ports, one synchronous write port.; x0 always reads 0, whatever was written to it.; No reset is needed.
- What is an example input and output for RISC-V Step 2: Register File?
- Input we=1, rd=3, wd=0xCAFE0003, rising edge gives output x3 = 0xCAFE0003. Ordinary write
- Which Verilog concepts does RISC-V Step 2: Register File practise?
- riscv, risc-v, register-file, sequential, cpu.