Skip to content

Chapter 5 — Single-Cycle CPU: Design & Implementation

In this chapter you will implement a minimal single-cycle CPU. Under a clock, you will connect combinational logic and storage elements into a system that can continuously execute a program. In a single-cycle design, each instruction completes fetch, decode, execute, memory access, and write-back within one clock cycle, with the architectural state (PC, registers, memory write) updating at the clock edge.

A single-cycle CPU is a great learning model because its structure and control are explicit and easy to debug. The target ISA subset for this chapter is a minimal RV32I set:

  • ADD, SUB, ADDI, LW, SW, BEQ

The instruction formats used by these instructions are summarized below.

Instrfunct7rs2rs1funct3rdopcode
ADD0000000rs2rs1000rd0110011
SUB0100000rs2rs1000rd0110011
Instrimm[31:20]rs1funct3rdopcode
ADDIimmrs1000rd0010011
LWimmrs1010rd0000011
Instrimm[31:25]rs2rs1funct3imm[11:7]opcode
SWimm[11:5]rs2rs1010imm[4:0]0100011
BEQimm[12,10:5]rs2rs1000imm[4:1,11]1100011

Table 5.1: Minimal instruction subset and encodings for the single-cycle CPU labs. Note: RISC-V branch immediates are 2-byte aligned, so the lowest bit is always 0 and is not explicitly encoded; BEQ’s immediate effectively has 13 bits after reconstruction.

This chapter is organized in three layers:

  • Datapath construction (start from functional modules and wire a working datapath)
  • Control unit design (decode instructions into control signals)
  • System integration & testing (run small programs end-to-end)