A custom-built 16-bit processor with 32 bit instruction format designed using Verilog HDL. The processor supports arithmetic, logical, memory, and control flow operations with a RISC-style instruction set. This project demonstrates core concepts of CPU design including FSM-based control, instruction decoding, ALU design, memory interfacing, and condition flags.
- 32 general-purpose registers (
GPR[0]
toGPR[31]
) - 16-entry instruction memory (
inst_mem
) - 16-entry data memory (
data_mem
) - ALU operations:
- Arithmetic:
ADD
,SUB
,MUL
- Logical:
AND
,OR
,XOR
,XNOR
,NAND
,NOR
,NOT
- Arithmetic:
- Data transfer:
- Move between GPRs, SGPR, and memory
- Load/store from external
din
and todout
- Control flow:
- Unconditional and conditional jumps (
JUMP
,JCARRY
,JZERO
, etc.)
- Unconditional and conditional jumps (
- FSM-based control unit with 6 states
- Condition flags:
Zero
,Sign
,Carry
,Overflow
- Support for immediate mode or register mode operations
. βββ top.v # Main Verilog module for the processor βββ inst_data.mem # Instruction memory file (binary format) βββ Makefile # (Optional) Compilation or simulation setup βββ README.md # Project documentation
Each instruction is 32 bits:
[31:27] opcode | [26:22] rdst | [21:17] rsrc1 | [16] imm_mode | [15:11] rsrc2 | [15:0] imm_data
Supports both immediate and register mode addressing based on imm_mode
.
- FSM cycles through:
idle β fetch β decode/execute β delay β next β halt check
- Instructions are fetched from
inst_mem
sequentially using a program counter. - Each instruction is decoded, executed, and relevant flags (
carry
,zero
, etc.) are updated. - Based on flag and instruction, PC is either incremented or updated (jump).
- Output (if any) is written to
dout
, data is read fromdin
.
You can simulate the design using tools like:
- ModelSim / Questa
- Vivado (Xilinx)
- Icarus Verilog + GTKWave
Write your instruction set in binary into the inst_data.mem
file. Example format:
00001xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 00010xxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
Each line represents a 32-bit instruction.
Aditya Padamwar
If you use or modify this processor, feel free to fork the repo and contribute!
This project is released under the MIT License. Feel free to use it for educational or commercial purposes with attribution.