Skip to content
baohoang037Public

About

Simple 8-bit RISC CPU - Verilog RTL Design & Verification

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SCPU – A Simple 8-bit CPU (Verilog RTL)

A small 8-bit RISC-style processor core written in Verilog, with a full design specification, a verification plan, and a self-checking testbench. The project is set up to run in Xilinx Vivado .

This is a learning project that contains the main parts of a real CPU (instruction fetch, decode, register file, ALU, control) while staying small enough to read end-to-end.

Block diagram


Features

  • 8-bit data path, 8-bit program counter
  • 16-instruction RISC-style instruction set (4-bit opcode)
  • Shared 256-byte memory for program and data
  • Four general-purpose registers (R0–R3)
  • ALU: AND, OR, ADD, SUB
  • 1 / 2 / 3 clock cycles per instruction depending on type
  • Synchronous, active-low reset

Architecture

The core has three blocks:

Block Responsibility
FETCH Memory, Program Counter (PC), Instruction Register (IR), Data Register (DR)
DECODER Decodes the opcode, generates control signals, holds the register file R0–R3
EXECUTE ALU (AND / OR / ADD / SUB)

The instruction format is two bytes: the first byte holds the opcode, Rd and Rs; the second byte (when used) holds an 8-bit immediate.

Instruction format

Repository layout

.
├── rtl/                    # Synthesizable RTL
│   ├── scpu_top.v          # Top module (connects the 3 blocks)
│   ├── scpu_fetch.v        # FETCH: memory, PC, IR, DR
│   ├── scpu_decoder.v      # DECODER: control + register file
│   ├── scpu_execute.v      # EXECUTE: ALU
│   ├── scpu_define.vh      # Global `define
│   └── scpu_parameter.vh   # Opcode parameters
├── sim/
│   ├── scpu_tb.v           # Self-checking testbench
│   └── scpu.romcode        # Demo program (binary, loaded by $readmemb)
├── scripts/
│   ├── create_vivado_project.tcl   # One-command Vivado project setup
│   └── run_iverilog.sh             # Quick command-line simulation
├── doc/
│   ├── SCPU_Design_Specification.pdf / .docx
│   ├── SCPU_register_checklist.xlsx # Verification plan
│   └── img/                         # Diagrams
└── README.md

Demo program

The included program (sim/scpu.romcode) computes 3 + 2 + 1 = 6 with a counting loop. It exercises immediate load, the ALU, a conditional branch, and an unconditional jump:

        LI  R0, 3        ; counter = 3
        LI  R1, 0        ; sum     = 0
        LI  R2, 1        ; step    = 1
loop:   ADD R1, R0       ; sum     = sum + counter
        SUB R0, R2       ; counter = counter - 1
        JNE R0, loop     ; repeat while counter != 0
        NOP
done:   JMP done         ; halt

Expected final state: R0 = 0x00, R1 = 0x06, R2 = 0x01.

How to run

Option A — Vivado (GUI or batch)

# From the repo root, in the Vivado Tcl console:
source scripts/create_vivado_project.tcl
launch_simulation

Or from a terminal:

vivado -mode batch -source scripts/create_vivado_project.tcl

The script adds all sources, sets rtl/ as a Verilog include directory (so the .vh headers resolve), marks the headers as Verilog Header, and copies the program file into the simulation run directory. See doc/VIVADO_SETUP.md for the manual GUI steps.

Option B — Icarus Verilog (no Vivado)

./scripts/run_iverilog.sh

Expected output:

*** TEST PASSED ***  3 + 2 + 1 = 6

Documentation

Notes and limitations

SCPU is a teaching core and keeps the hardware simple:

  • It uses a single memory port, so a memory-access instruction (LWR/SWR/LWI/SWI) or a taken jump needs one extra realignment cycle before the next instruction is fetched cleanly. Demo programs are written with this in mind.
  • LWR/SWR (register-addressed memory) are the recommended way to access data memory.
  • Registers are unsigned, so JLT (Rd < 0) never takes the branch in this version. Use JEQ, JNE, or JGT.

See section 4.6 of the design specification for details.

👨‍💻 Author


⚡ Hoàng Ngọc Gia Bão

Integrated Circuit Design · FPT University


📬 Connect with me


Email Gia Bão

baohoang037@gmail.com


Gia Bão on LinkedIn

View professional profile ↗


Gia Bão on GitHub

@baohoang037 ↗

About

Simple 8-bit RISC CPU - Verilog RTL Design & Verification

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages