1Learning Outcomes¶
Describe the main state elements on the single-cycle RISC-V datapath.
Identify when data is written on synchronous state elements on the RISC-V datapath.
Compare and contrast read and write behaviors of RISC-V state elements.
🎥 Lecture Video
As mentioned in the previous section, a CPU has two types of elements, reflecting the design of many digital logic systems.
State elements that contain state: registers and memory
Combinational Logic Blocks that operate on data values: ALU, other combinational logic, etc.
In this section, we discuss the state elements needed in a RISC-V processor. We will discuss and introduce the combinational logic blocks as we build out the full datapath.
1.1Program Counter¶
The Program Counter is a 32-bit register in Figure 1 and holds the value of the current instruction, i.e., instruction to execute in the current clock cycle.

Figure 1:The Program Counter, PC, is a single 32-bit register in the CPU.
PC Signals
Input:
Data: N-bit data input bus
Control: Write Enable bit. 1: asserted/high, 0: deasserted/low.
Clock signal.
Output:
Data: N-bit data output bus
Behavior:
Read: At all other times, Data Out will not change; it will output its current value.
Write: Rising-edge triggered. On rising clock edge, if Write Enable is 1, set Data Out to Data In (delay of clk-to-q).
1.2Register File (Regfile)¶
The Register File (regfile, or Reg[]) has 32 registers: register numbers x0 to x31.

Figure 2:The RegFile is symbolically written as Reg[] and is composed of registers x0 to x31.
Table 1:Regfile signals. Course project signal names, if different, are in parentheses.
| Name | Direction | Bit Width | Description |
|---|---|---|---|
rs1 (ReadIndex1) | Input | 5 | Determines which register’s value is sent to the rdata1 (ReadData1) output |
rs2 (ReadIndex2) | Input | 5 | Determines which register’s value is sent to the rdata2 (ReadData2) output |
rd (WriteIndex) | Input | 5 | The register to write to on the next rising edge of the clock (if RegWEn is 1) |
wdata (WriteData) | Input | 32 | The data to write into rd on the next rising edge of the clock (if RegWEn is 1) |
RegWEn | Input | 1 | Determines whether data is written to the register file on the next rising edge of the clock |
clk | Input | 1 | Clock input |
rdata1 (ReadData1) | Output | 32 | The value of the register identified by rs1 (ReadIndex1) |
rdata2 (ReadData2) | Output | 32 | The value of the register identified by rs2(ReadIndex2) |
Behavior:
Registers are accessed via their 5-bit register numbers:
R[rs1]:rs1selects register to put onrdata1bus out.R[rs2]:rs2selects register to put onrdata2bus out.R[rd]:rdselects register to be written viawdatawhenRegWEnis set to 1.
Read: As long as
rs1andrs2are valid, thenrdata1andrdata2are valid after access time, regardless of whatRegWEnis set to.Write: Rising-edge-triggered write. On rising clock edge, if
RegWEnis set to 1, writewdatatoR[rd].
1.3DMEM: Data Memory¶
For this class, memory is “magic.” Assume a 32-bit byte-addressed memory space, and memory access occurs with 32-bit words. We go into more detail with our course projects.
For our single-cycle datapath, we must access memory twice: once during IF (Instruction Fetch) to read the instruction from memory, and once during MEM (Memory Access) if we load/store data from/to memory. We therefore need two memory blocks: IMEM and DMEM for instruction memory and data memory, respectively.[1]
The Data Memory block DMEM has edge-triggered writes, just like Reg[].

Figure 3:The Data Memory block DMEM. Read operations behave like combinational logic, whereas write operations occur on the rising clock edge.
Table 2:DMEM signals. Course project signal names, if different, are in parentheses.
| Name | Direction | Bit Width | Description |
|---|---|---|---|
addr (MemAddress) | Input | 32 | The address in memory to read from or write to |
wdata (MemWriteData) | Input | 32 | Data to write to memory |
MemRW (MemWriteMask) | Input | 4 | The write enable mask for writing data to memory |
clk | Input | 1 | Clock input |
rdata (MemReadData) | Output | 32 | Data at addr (MemAddress) from memory |
Behavior: DMEM read/writes behave similarly to Regfile, though now we provide memory addresses as input, not register numbers.
Read: Address
addrselects word to put onrdatabus. IfMemRWis 0 andaddris valid, thenrdatais valid after access time.Write: Rising-edge-triggered write. On rising clock edge, if
MemRWis set to 1, writewdatato addressaddr.
1.4IMEM: Instruction Memory¶
The Instruction Memory block IMEM is a read-only memory that fetches instructions.[2]

Figure 4:In our CPU, the Instruction Memory block IMEM is read-only and behaves like combinational logic.
Table 2:IMEM signals. Course project signal names, if different, are in parentheses.
| Name | Direction | Bit Width | Description |
|---|---|---|---|
addr (N/A) | Input | 32 | The address in memory to read from |
inst (Instruction) | Output | 32 | The instruction at memory address addr(ProgramCounter) |
Behavior:
Read: Address
addrselects word to put oninstbus. Ifaddris valid, theninstis valid after access time.