CS With NehalCS With Nehal

RISC-V Datapath Simulator

Type one RISC-V instruction and highlight the exact wires, components and control signals it uses in the single-cycle datapath.

1. Build the datapath for

R-type
I-type
S-type
SB-type
U-type
UJ-type

Hardware for: R-type arithmetic, I-type load, S-type store, SB-type branch. Try two or three instructions to see how the datapath grows.

2. Run an instruction

Examples:

Formats: R-type arithmetic: rd, rs1, rs2 · I-type load: rd, offset(rs1) · S-type store: rs2, offset(rs1) · SB-type branch: rs1, rs2, offset. Registers can be x0–x31 or ABI names (a0, t1…).

Datapathcyan = data used, amber = control signal set, grey = not used, dashed = don't care
RISC-V single-cycle datapathPCAdd4Read addressInstruction[31-0]Instructionmemory[6-0][19-15][24-20][11-7][31-0][30,14-12]ControlBranchMemtoRegMemReadMemWriteALUOpALUSrcRegWriteRead register 1Read register 2Write registerWrite dataRead data 1Read data 2RegistersImm Gen3264Shift left 1Add01Mux012Mux01MuxALUZeroresultALU controlData memoryAddressWrite dataRead dataPCSrc

Details

Point at (or tap) any part or wire of the datapath to see what it does and, after running an instruction, the value it carries.

Instruction

Run an instruction to see its 32 bits split into fields.

Control signals

SignalR arithmeticI loadS storeSB branch
RegWrite1100
ALUSrc0110
ALUOp10000001
MemRead0100
MemWrite0010
MemtoReg01XX
Branch0001

Only signals this datapath needs are listed. Hover a row for its meaning; X = does not matter.

What happens in this cycle

Run an instruction to see each stage explained with its real values.

Show values as

Registers

Click a value to edit it. Read and written registers are marked.

x0zero
x1ra
x2sp
x3gp
x4tp
x5t0
x6t1
x7t2
x8s0
x9s1
x10a0
x11a1
x12a2
x13a3
x14a4
x15a5
x16a6
x17a7
x18s2
x19s3
x20s4
x21s5
x22s6
x23s7
x24s8
x25s9
x26s10
x27s11
x28t3
x29t4
x30t5
x31t6

Data memory

256 bytes as 8-byte doublewords (little-endian). Click a value to edit it.

[0]
[8]
[16]
[24]
[32]
[40]
[48]
[56]
[64]
[72]
[80]
[88]
[96]
[104]
[112]
[120]
[128]
[136]
[144]
[152]
[160]
[168]
[176]
[184]
[192]
[200]
[208]
[216]
[224]
[232]
[240]
[248]

About This Simulation

This RISC-V datapath simulator lets you choose which instructions the datapath must support, then run one. Every wire, component and control signal the instruction uses lights up, and registers and data memory keep their values between instructions.

Features

  • R-type, I-type, load, store, branch and jump instructions
  • Active wires and components highlighted in the single-cycle datapath
  • Control signal values (RegWrite, ALUSrc, MemRead, MemWrite, MemtoReg, Branch, ALUOp)
  • Register file and data memory state kept between runs
  • Choose which instructions the datapath supports

Topics covered

  • RISC-V
  • Single-Cycle Datapath
  • Control Unit and Control Signals
  • ALU
  • Register File
  • Instruction Formats

Explanation

A datapath is the hardware that executes instructions: the program counter, instruction memory, register file, ALU, data memory and the multiplexers that connect them. In a single-cycle datapath every instruction finishes in one clock cycle, and the control unit sets the signals that decide which paths are used.

How it works

  1. Fetch: the PC addresses instruction memory, and PC + 4 is computed for the next instruction.
  2. Decode: the opcode goes to the control unit, the register fields read rs1 and rs2, and the immediate generator builds the immediate.
  3. Execute: the ALU adds, subtracts, compares or computes an address, with ALUSrc choosing between rs2 and the immediate.
  4. Memory: loads read data memory (MemRead) and stores write it (MemWrite).
  5. Write back: MemtoReg chooses the ALU result or loaded data to write to rd when RegWrite is 1. For branches, the PC becomes PC + offset if the condition holds.

Why it matters

Understanding the datapath explains how software becomes hardware actions, why some instructions are slower, and how pipelining works. Tracing control signals for a given instruction is a standard question in computer architecture courses such as CSE340.

Frequently Asked Questions

What are the control signals in a RISC-V single-cycle datapath?

The main ones are RegWrite, ALUSrc, MemRead, MemWrite, MemtoReg, Branch and ALUOp. They choose which multiplexer inputs are used, whether registers or memory are written, and which ALU operation is performed.

Which components does a load (lw) instruction use?

All five stages: instruction memory, register file (read rs1), immediate generator, ALU (address = rs1 + offset), data memory (read) and the register file again (write rd). That makes it the longest path in the single-cycle datapath.

Why is a single-cycle datapath inefficient?

The clock period must fit the slowest instruction (usually a load), so faster instructions waste time. Pipelining fixes this by overlapping the stages of several instructions.

What does ALUSrc do?

It controls the multiplexer in front of the ALU's second input: 0 selects register rs2 (R-type and branches) and 1 selects the immediate (I-type, loads and stores).

Related Simulations