Back to projects

02 / Digital Design · VHDL

5-Stage Pipelined ARM Processor

Course: Computer Architecture Discipline: Digital design in VHDL Date: 2025

A complete LEGv8-subset ARM-style processor in VHDL, built from the ground up as a single-cycle datapath, then pipelined into five stages with hazard detection and data forwarding, and verified via waveform analysis.

Overview

As the term project for my Computer Architecture course, I designed and implemented a simplified ARM-like processor using VHDL. The processor supports a subset of ARM instructions (specifically LEGv8), including arithmetic operations, memory access, and control flow.

The project began with the foundational components: PC, instruction and data memory, register file, and ALU. I first wired these together into a single-cycle architecture to validate basic functionality before transitioning to a pipelined design. That shift introduced challenges around instruction dependencies and timing, which I addressed through hazard detection and data forwarding.

Single-cycle LEGv8 datapath: PC, instruction memory, register file, ALU, and data memory wired as one combinational path with the control unit driving Reg2Loc, Branch, MemRead, MemtoReg, ALUOp, MemWrite, ALUSrc, and RegWrite
Single-cycle datapath, the starting point: one instruction per clock, no pipeline registers.

Pipelining the datapath

The pipeline follows the classic five-stage approach: Instruction Fetch, Instruction Decode, Execute, Memory Access, and Write Back. Each stage operates concurrently with the others, creating a processing pipeline that can theoretically complete one instruction per clock cycle. The real complexity comes from data hazards: situations where instructions depend on results from previous instructions still moving through the pipeline.

Five-stage pipelined LEGv8 datapath with IF/ID, ID/EX, EX/MEM, and MEM/WB pipeline registers separating the stages, and control signals carried forward through the register stack
The same datapath cut into five stages by the IF/ID, ID/EX, EX/MEM, and MEM/WB pipeline registers. Control signals ride along in the registers rather than being regenerated per stage.

Most of the bugs that actually cost time weren't in the hazard logic itself. Several pipeline registers and internal signals weren't initialized to a known value at reset, so simulations would run clean until a specific reset timing exposed garbage propagating through the datapath. The rest were classic hazard bugs: read-after-write cases where a dependent instruction read a stale register value before forwarding caught up, and write-after-read cases where the register file wrote its new value before an earlier stage had read the old one. Both took cycle-by-cycle waveform tracing to pin down.

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity SingleCycleCPU is
port(clk :in STD_LOGIC;
     rst :in STD_LOGIC;
     --Probe ports used for testing
     --The current address (AddressOut from the PC)
     DEBUG_PC : out STD_LOGIC_VECTOR(63 downto 0);
     --The current instruction (Instruction output of IMEM)
     DEBUG_INSTRUCTION : out STD_LOGIC_VECTOR(31 downto 0);
     --DEBUG ports from other components
     DEBUG_TMP_REGS : out STD_LOGIC_VECTOR(64*4 - 1 downto 0);
     DEBUG_SAVED_REGS : out STD_LOGIC_VECTOR(64*4 - 1 downto 0);
     DEBUG_MEM_CONTENTS : out STD_LOGIC_VECTOR(64*4 - 1 downto 0)
);
end SingleCycleCPU;
The single-cycle top level, before it was pipelined. Past the clock and reset, every port on it is a debug probe, so the testbench can watch the program counter, the current instruction, and the register and memory contents from outside the design.
CPU simulation waveform
GTKWave simulation waveform, instruction execution traced through the pipeline.

Verification

The debug ports are what let the testbenches check themselves. A testbench loads an instruction sequence, runs it, and compares the register file and memory contents against the end state that sequence should produce, so a failing program reports which value is wrong instead of leaving me to read a waveform and decide. GTKWave came after that, once a check had told me something was broken and I needed to find which stage broke it.

Image credits

  • Single-cycle and pipelined datapath diagrams: Patterson, David A., and John L. Hennessy. Computer Organization and Design: The Hardware/Software Interface (Arm® Edition). ISBN 978-0-12-801733-3.

Textbook diagram used for educational purposes under fair use. Code screenshots and simulations are personal development work.