225 CRP - Custom Risc Processor

225 : CRP - Custom Risc Processor

Design render

How it works

The 8-Bit CRP CPU is a simple, custom-designed processor implemented in Verilog.
It follows a classic Von Neumann architecture, where instructions and data share the same memory space. The CPU is based on a multicycle design, meaning that each instruction takes a variable number of clock cycles to complete.

The main components of the CPU include:

  • ALU (Arithmetic Logic Unit): Performs arithmetic operations like addition and subtraction, as well as logical operations such as AND, OR, XOR, shifts (LSR, LSL/ASL, ASR), and comparison operations.
  • Registers: 16 general-purpose 8-bit registers, with registers 14 and 15 reserved for memory addressing in LD and ST instructions (R14 = lower 8 bits, R15 = upper 7 bits). A dedicated stack pointer starts at 0x7FFF and counts downward. The program counter / instruction pointer (PC/IP) starts at 0x0000 and increments according to the instruction.
  • Controller: Decodes instructions and generates control signals to orchestrate data movement, ALU operations, memory access, and branching.
  • Datapath: Connects all components and manages the flow of data between registers, ALU, and memory.
  • Multiplexers: Select ALU and register file inputs depending on the current instruction.
  • State Counter: Manages the instruction execution cycle, controlling fetch, decode, execute, and writeback stages.

The CPU supports 16-bit instruction width. Instructions are categorized as R-type, I-type, and J-type:

  • R-type: Register instructions (e.g., ADD, SUB, AND, OR). Includes a function field for the exact operation.
  • I-type: Immediate operations, using an 8-bit immediate value (e.g., ADDI, SUBI, ANDI).
  • J-type: Jump instructions, which are relative and may be signed or unsigned depending on the opcode.

The CPU communicates with external memory via:

  • 8-bit data bus: DI0–DI7 for memory input, DO0–DO7 for memory output.
  • 15-bit address bus: A0–A14 for memory addressing.
  • Write Enable: WE Signals a memory write request.

Memory write protocol:

  1. Clock cycle 1: Place the 8-bit data to write on DO0–DO7 and set WE high. The data is temporarily stored externally.
  2. Clock cycle 2: Provide the 15-bit target address on A0–A14. Memory writes the previously buffered data to this address.

Instruction storage in memory:

  • Each 16-bit instruction occupies two consecutive addresses:
    • Even addresses: lower 8 bits of the instruction
    • Odd addresses: upper 8 bits of the instruction

How to test

  1. Set up external memory

    • Use a memory module with read/write capability and 15-bit address lines.
    • Connect CPU data input pins (DI0–DI7) to memory output pins.
    • Connect CPU data output pins (DO0–DO7) to memory input pins.
    • Connect CPU address pins (A0–A14) to memory address pins.
    • Connect CPU write enable pin (WE) to memory WE input via an external buffer.
  2. Load a program

    • The complete instruction set for binary translation can be found in Appendix A.
    • Instructions are 16 bits wide and occupy two consecutive memory addresses:
      • Even addresses: lower 8 bits
      • Odd addresses: upper 8 bits
  3. Reset the CPU state

    • Set rst_n low briefly while toggling the clock:
      1. rst_n = 0, clk = 1
      2. clk = 0
      3. rst_n = 1
  4. Provide a clock signal

    • The CPU is multi-cycle; instructions take multiple clock cycles.
    • After reset, the program counter (PC/IP) begins at 0x000.

External hardware

  • Memory module: 8-bit data, 15-bit address, supports read/write operations.
  • Buffer register: Controlled by WE, it captures the 8-bit data bus (DO0–DO7) for use in the next clock cycle.
  • Clock source: Provides the clock signal for multicycle operation.

Appendix A: Instruction Set Overview

Mnemonic Opcode Operands Description Clock
MOV 0000 Rd, Rr, 0000 Copy from Rr to Rd 3
ADD 0000 Rd, Rr, 0001 Add Rr to Rd 3
SUB 0000 Rd, Rr, 0010 Subtract Rr from Rd 3
AND 0000 Rd, Rr, 0011 Bitwise AND 3
OR 0000 Rd, Rr, 0100 Bitwise OR 3
XOR 0000 Rd, Rr, 0101 Bitwise XOR 3
LD 0000 Rd, xxxx, 0110 Load from memory to Rd 4
ST 0000 Rd, xxxx, 0111 Store Rd to memory 4
PUSH 0000 Rd, xxxx, 1000 Push Register on Stack 4
POP 0000 Rd, xxxx, 1001 Pop Register from Stack 5
PUSHF 0000 xxxx, xxxx, 1010 Push Flags on Stack 4
POPF 0000 xxxx, xxxx, 1011 Pop Flags from Stack 4
LSR 0000 Rd, Rr, 1100 Logical Shift Right 3
LSL 0000 Rd, Rr, 1101 Logical Shift Left 3
ASR 0000 Rd, Rr, 1110 Arithmetic Shift Right 3
CMP 0000 Rd, Rr, 1111 Compare Rd with Rr 3
CMPI 0001 Rd, immediate Compare Rd with Immediate 3
ADDI 0010 Rd, immediate Add Immediate to Rd 3
SUBI 0011 Rd, immediate Subtract Immediate from Rd 3
ANDI 0100 Rd, immediate Bitwise AND with Immediate 3
ORI 0101 Rd, immediate Bitwise OR with Immediate 3
XORI 0110 Rd, immediate Bitwise XOR with Immediate 3
MOV 0111 Rd, immediate Load Immediate into Rd 3
RJMP 1000 address Relative Jump 3
RET 1001 1101, 1101, xxxx Subroutine Return¹ 7
RCALL 1010 address Relative Subroutine Call 6
JE 1011 address Jump If Equal 3
JNE 1100 address Jump If Not Equal 3
JB 1101 address Jump If Below, Unsigned 3
JAE 1110 address Jump If Above Or Equal, Unsigned 3
JL 1111 address Jump If Less, Signed 3

Legend

  • Rd – Destination register (4-bit)
  • Rr – Source register (4-bit)
  • Immediate – 8-bit constant embedded in instruction
  • Address – 12-bit relative address; MSB is sign-extended for overflow
  • x – Ignored bit/operand
  • ¹RET – Uses an internal temporary register for storing return address from stack. Here: 1101

IO

#InputOutputBidirectional
0DI0A0/DO0A8
1DI1A1/DO1A9
2DI2A2/DO2A10
3DI3A3/DO3A11
4DI4A4/DO4A12
5DI5A5/DO5A13
6DI6A6/DO6A14
7DI7A7/DO7WE

Chip location

Controller Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux tt_um_chip_rom (Chip ROM) tt_um_factory_test (Tiny Tapeout Factory Test) tt_um_oscillating_bones (Oscillating Bones) tt_um_tt_tinyQV (TinyQV - Crowdsourced Risc-V SoC) tt_um_rejunity_atari2600 (Atari 2600) tt_um_rejunity_lgn_mnist (LGN hand-written digit classifier (MNIST, 16x16 pixels)) tt_um_izh_neuron_lite (LIF Neuron) tt_um_blptrk_weaving01 (weaving in silicon #1) tt_um_rte_eink_driver (E-ink display driver) tt_um_bleeptrack_prism (Prism) tt_um_zerotoasic_logo_screensaver (VGA Screensaver with Zero to ASIC Logo) tt_um_kianV_rv32ima_uLinux_SoC (KianV uLinux SoC) tt_um_nefelimet_updown_cntr (3-bit up-down counter) tt_um_wokwi_434917577229968385 (LIF neuron) tt_um_wokwi_434917320361309185 (TinyTapeout 2025) tt_um_wokwi_434917171311441921 (MC first Wokwi) tt_um_wokwi_434917344830882817 ('') tt_um_wokwi_434918300941464577 (WowkiProject) tt_um_wokwi_434917453767462913 (Mini Calculator v1) tt_um_wokwi_434917219039482881 (and) tt_um_wokwi_434917025263649793 (DigOTA) tt_um_wokwi_434917044822739969 (TinyTapeoutWorkshop) tt_um_wokwi_434921821909078017 (and gate) tt_um_wokwi_434917167895180289 (Encoder) tt_um_wokwi_434917143298726913 (Chip design from Wokwi) tt_um_wokwi_434921804663145473 (Tapeout try) tt_um_wokwi_434917374201501697 (dummy) tt_um_wokwi_434917318393129985 (Tiny Tapeout Template Copy) tt_um_wokwi_434917632188986369 (Timo 1) tt_um_wokwi_434917842159020033 (And Gate) tt_um_wokwi_434917427319226369 (Tiny Tapeout Chip) tt_um_wokwi_434917260383792129 (Tiny Tapeout Workshop Project by Nick Figner) tt_um_wokwi_434917040492120065 (4 bit incrementer) tt_um_wokwi_434917990496885761 (Projekt) tt_um_wokwi_434917381796339713 (Nils Tinytapeout Proj) tt_um_wokwi_434917317189363713 (tinytapeoutchip) tt_um_wokwi_434917679388544001 (tiny tapeout chip) tt_um_wokwi_434917506576906241 (ToDo) tt_um_wokwi_434917139713644545 (in progress) tt_um_wokwi_434917382645687297 (numbers) tt_um_wokwi_434917816595781633 (number display) tt_um_wokwi_434918311072808961 (GG) tt_um_wokwi_434917362908337153 (noclue) tt_um_wokwi_434917682511205377 (Random) tt_um_wokwi_434925031692840961 (demo-tiny) tt_um_wokwi_434917760986646529 (Barans erster Template Design) tt_um_wokwi_434917419779963905 (Tapeout Test1) tt_um_wokwi_434917684709021697 (Tiny Tapeout Template Copy_Orion) tt_um_wokwi_434918956220790785 (Simple classification perceptron ) tt_um_wokwi_434918068909406209 (Tiny Tapeout) tt_um_parx (example-verilog) tt_um_wokwi_434917624377094145 (brostarscard) tt_um_urish_simon (Simon Says memory game) tt_um_emmk_riscv (ENSEIRB-MATMECA RISC-V ASIC) tt_um_abhinav8prasad_dds (8-bit DDS sine wave generator) tt_um_wokwi_436554456427191297 (OCDCpro TT key lock test design IHP) tt_um_wokwi_434391222509479937 (4-Bit Adder) tt_um_ihp_logo_screensaver (VGA Screensaver with the IHP Logo) tt_um_pqn (PQN Model with Verilog) tt_um_Xelef2000 (RNG) tt_um_gamepad_pmod_demo (Gamepad Pmod Demo) tt_um_anujic (Morse Code Trainer) tt_um_rodald_cpr (CRP - Custom Risc Processor) tt_um_alif_dual_unileak (LIF Neuron) tt_um_riscv_mini_ihp (RISC-V Mini IHP) tt_um_wokwi_434917200607612929 (test_design) tt_um_alif_single_dualleak (Simple LIF Neuron) tt_um_blptrk_weaving02 (weaving in silicon #2) tt_um_blptrk_weaving03 (weaving in silicon #3) tt_um_blptrk_weaving04 (weaving in silicon #3) tt_um_dumbrv_yliu_hashed (DUMBRV) tt_um_iz_neuron (IZH Neuron) tt_um_test_chip_pius (Verilog OR-Gate) tt_um_pwm_block (PWM_SPI) tt_um_2048_vga_game (2048 sliding tile puzzle game (VGA)) tt_um_dpi_adexp (AdExp DPI Neuron ) tt_um_urish_sic1 (SIC-1 8-bit SUBLEQ Single Instruction Computer) tt_um_cedrichirschi_sar (SAR ADC Controller) tt_um_htfab_yadge (Yet Another Diffraction Grating Experiment) tt_um_ds_comp_adc (Delta Sigma Comparator Based ADC) tt_um_tinytapeout_logo_screensaver (VGA Screensaver with Tiny Tapeout Logo) Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available Available