This project aims to create an educational 16-bit single-cycle CPU with a MIPS-like instruction set. Featuring R-type, I-type and J-type instruction capabilities along with a structural and fully documented datapath diagram that fully aligns with the VHDL code.
This project implements a 16-bit MIPS-like single-cycle CPU using VHDL. The processor is not a full MIPS implementation; instead, it uses a custom 16-bit instruction set inspired by common RISC/MIPS datapath concepts. The design focuses on educational clarity, structural organization, and direct correspondence between the VHDL source code and the CPU datapath diagram.
The CPU a single-cycle architecture, which means each instruction is fetched, decoded, and executed within one clock-cycle. The processor includes the main components and building blocks commonly found in a basic RISC datapath:
- Program Counter (PC)
- Instruction Memory (IM)
- Control Unit (CU)
- Register File
- Arithmetic Logic Unit (ALU)
- Data Memory (DM)
- Adders
- Multiplexers (MUXes)
- Sign Extension Blocks
- Shift Left Logic Blocks
- Concantenation Blocks
Figure 1 – Datapath of the single-cycle CPU.
All instructions use a fix 16-bit format:
| Bits | Field | Description |
|---|---|---|
| 15–12 | opcode | Selects the instruction |
| 11–8 | rd | Destination register or second source register |
| 7–4 | rs | First source register |
| 3–0 | rt / immediate | Second source register or signed 4-bit immediate |
The CPU supports arithmetic, logic, immediate, memory, branch, jump, and link instructions. Although the field names are inspired by MIPS terminology, the instruction encoding is custom.
The top-level CPU datapath is implemented structurally in CPU.vhd. The Program Counter (PC) provides the address of the current instruction to Instruction Memory. Since each instruction is 16 bits wide, the PC normally increments by 2 after each instruction.
The next PC value is selected by a multiplexer controlled by the PCSrc signal.
PCSrc |
Next PC source | Used by |
|---|---|---|
00 |
PC + 2 |
Normal sequential execution |
01 |
Branch target | BEQ, BNE |
10 |
Jump target | J, JAL |
11 |
Register target | JR, JALR |
The Control Unit generates all major control signals for the processor, including ALU operation, memory read/write, register write, ALU source selection, register source selection, write-back selection, and PC source selection.
The PCSrc signal controls the next Program Counter value:
| PCSrc | Next PC source |
|---|---|
00 |
PC + 2 |
01 |
Branch target |
10 |
Jump target |
11 |
Register jump target |
This allows the CPU to support normal sequential execution, conditional branches, immediate jumps, and register-based jumps.
The ALU is implemented structurally using 1-bit ALU slices. Each 1-bit ALU uses a full adder as its core building block, with input-control logic allowing the same hardware structure to support multiple operations.
The ALU supports arithmetic and logic operations such as addition, subtraction, AND, OR, XOR, and set-less-than. The ALU also produces a status output used by the Control Unit for conditional branch instructions.
This design was chosen to show how a multi-bit ALU can be constructed from smaller hardware units instead of being written only as a high-level behavioral block.
The CPU uses a 16-register file, where each register is 16 bits wide. Most instructions write results to the rd field. Link instructions such as JAL and JALR write the return address into register R15.
The write-back datapath can select between:
- ALU result
- Data Memory output
- PC + 2 for link instructions
This allows the same register file to support arithmetic instructions, load instructions, and jump-and-link instructions.
Instruction memory and data memory are implemented as separate memory components. The CPU uses byte-addressed memory, while instructions and data values are 16 bits wide.
Instruction files store one byte per line. Since the memory system uses little-endian ordering, each 16-bit instruction is stored with the low byte first and the high byte second.
For example, the instruction word 4101 is stored as:
00000001
01000001