# jayjain2365/4bit-processor-verilog architecture

> Architecture diagram of the GitHub repository jayjain2365/4bit-processor-verilog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jayjain2365/4bit-processor-verilog
- Repository: https://github.com/jayjain2365/4bit-processor-verilog

## Overview

This repository is a small RTL design for a **4-bit processor** implemented in **Verilog HDL** and packaged as a **Xilinx Vivado** project. The architecture is intentionally narrow: it is a self-contained, simulation-oriented CPU datapath with four classic stages—fetch, decode, execute, and write-back.

The core design lives under `Alu_4bit.srcs/sources_1/new/` and is split into clear hardware boundaries:
- `fetch_unit.v`
- `decode_unit.v`
- `execute_unit.v`
- `write_back.v`
- `processor_top.v` as the integration point

The top-level module, `processor_top.v`, is the main architectural boundary. It wires the stage modules together into a single instruction flow, so the diagram should show data moving from fetch to decode to execute to write-back, with control and results feeding back into the register storage.

The **fetch stage** maintains the **program counter (PC)** and supplies the next instruction. In the repository’s described model, this stage is responsible for instruction retrieval and PC advancement, so it should be drawn as the entry point of the processor pipeline.

The **decode stage** interprets the instruction fields—especially opcode and register selectors—and reads source operands from the **register file**. The README specifies a **4-register file**, **4-bit wide**, with **two read ports** and **one write port**, which is a key architectural feature to capture in the diagram.

The **execute stage** performs the actual ALU work. Supported operations are limited to simple 4-bit instructions: **ADD, SUB, AND, OR, MOV, and NOP**. This stage also generates status/condition outputs as described in the README, so it is the arithmetic/logic boundary of the design.

The **write-back stage** commits the execution result back into the register file. Architecturally, this is the only stage that updates architectural state, so it should be shown as the point where computed results become visible to later instructions.

The design appears to be a **single-instruction datapath model**, not a superscalar or deeply pipelined CPU. Even though the stages are separated structurally, the repository emphasis is on demonstrating the processor cycle rather than out-of-order execution, hazard handling, or caching.

Validation is done through `Alu_4bit.srcs/sim_1/new/processor_tb.v`, which is the simulation testbench. The testbench drives the top-level processor and observes PC progression, instruction decode, ALU results, and register updates in Vivado Simulator.

The `screenshots/` folder is documentation-only support material for waveform evidence of correct behavior. It does not participate in the hardware architecture, but it supports the verification story.

At the project level, the main external tooling boundary is **Xilinx Vivado**, which provides synthesis/simulation context and the `.xpr` project file. There are no signs of software runtime, operating-system services, or external peripherals; this is a pure RTL and simulation repository.

If you are drawing an architecture diagram, the most important boxes are:
1. Fetch/PC
2. Decode/register read
3. Execute/ALU
4. Write-back/register update
5. Testbench around the top-level processor

The overall data flow is linear through those stages, with the register file providing the central state storage that decode reads from and write-back updates.

Main entry points: [`Alu_4bit.srcs/sources_1/new/processor_top.v`](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/processor_top.v) (Processor Top), [`Alu_4bit.srcs/sources_1/new/decode_unit.v`](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/decode_unit.v) (Decode), [`Alu_4bit.srcs/sources_1/new/write_back.v`](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/write_back.v) (Write Back), [`Alu_4bit.srcs/sim_1/new/processor_tb.v`](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sim_1/new/processor_tb.v) (Testbench)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rtl["Core RTL"]
  node_processor_top["Processor Top<br/>top module<br/>[processor_top.v]"]
  node_fetch_unit["Fetch<br/>pc/instruction<br/>[fetch_unit.v]"]
  node_decode_unit["Decode<br/>control/read<br/>[decode_unit.v]"]
  node_register_file[("Register File<br/>4x4 regs")]
  node_execute_unit["Execute<br/>alu<br/>[execute_unit.v]"]
  node_write_back["Write Back<br/>commit<br/>[write_back.v]"]
end

subgraph group_sim["Simulation"]
  node_processor_tb["Testbench<br/>simulation<br/>[processor_tb.v]"]
end

subgraph group_tooling["Tooling"]
  node_vivado_proj["Vivado Project<br/>xpr project<br/>[Alu_4bit.xpr]"]
end

subgraph group_docs["Docs"]
  node_screenshots["Waveforms<br/>evidence<br/>[README.md]"]
end

node_processor_tb -->|"stimulates"| node_processor_top
node_processor_top -->|"instantiates"| node_fetch_unit
node_fetch_unit -->|"instruction"| node_decode_unit
node_decode_unit -->|"reads"| node_register_file
node_register_file -->|"operands"| node_decode_unit
node_decode_unit -->|"control+operands"| node_execute_unit
node_execute_unit -->|"result"| node_write_back
node_write_back -->|"commit"| node_register_file
node_write_back -->|"next cycle"| node_fetch_unit
node_processor_top -.->|"observed by"| node_processor_tb
node_vivado_proj -.->|"contains"| node_processor_top
node_processor_tb -.->|"verified with"| node_screenshots

click node_processor_top "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/processor_top.v"
click node_fetch_unit "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/fetch_unit.v"
click node_decode_unit "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/decode_unit.v"
click node_execute_unit "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/execute_unit.v"
click node_write_back "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/write_back.v"
click node_processor_tb "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sim_1/new/processor_tb.v"
click node_vivado_proj "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.xpr"
click node_screenshots "https://github.com/jayjain2365/4bit-processor-verilog/blob/main/screenshots/README.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_processor_top,node_fetch_unit,node_decode_unit,node_register_file,node_execute_unit,node_write_back toneBlue
class node_processor_tb toneAmber
class node_vivado_proj toneMint
class node_screenshots toneRose
```

## Components

### Core RTL

Processor datapath and stage modules

- [Processor Top](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/processor_top.v): top module · Integrates fetch, decode, execute, and write-back into one CPU datapath · `Alu_4bit.srcs/sources_1/new/processor_top.v`
- [Fetch](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/fetch_unit.v): pc/instruction · Maintains the program counter and supplies the next instruction · `Alu_4bit.srcs/sources_1/new/fetch_unit.v`
- [Decode](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/decode_unit.v): control/read · Decodes opcode and register fields, and reads source operands · `Alu_4bit.srcs/sources_1/new/decode_unit.v`
- **Register File**: 4x4 regs · Central 4-register, 4-bit storage with two read ports and one write port
- [Execute](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/execute_unit.v): alu · Performs ADD, SUB, AND, OR, MOV, and NOP operations and produces status outputs · `Alu_4bit.srcs/sources_1/new/execute_unit.v`
- [Write Back](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sources_1/new/write_back.v): commit · Commits the ALU result back into architectural state · `Alu_4bit.srcs/sources_1/new/write_back.v`

### Simulation

Testbench and verification flow

- [Testbench](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.srcs/sim_1/new/processor_tb.v): simulation · Drives the processor top module and checks PC, decode, ALU, and register updates · `Alu_4bit.srcs/sim_1/new/processor_tb.v`

### Tooling

Vivado project and project context

- [Vivado Project](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/Alu_4bit.xpr): xpr project · Xilinx Vivado project container for synthesis and simulation · `Alu_4bit.xpr`

### Docs

Documentation and waveform artifacts

- [Waveforms](https://github.com/jayjain2365/4bit-processor-verilog/blob/main/screenshots/README.md): evidence · Captured simulation screenshots used as verification evidence · `screenshots/README.md`

## Connections

- Testbench → Processor Top: stimulates · Simulation harness drives the CPU top level
- Processor Top → Fetch: instantiates · Top-level wiring begins with instruction fetch
- Fetch → Decode: instruction · Next instruction and PC flow into decode
- Decode → Register File: reads · Decode extracts source operands from the register file
- Register File → Decode: operands · Read data returns to decode for execution setup
- Decode → Execute: control+operands · Opcode and operands are forwarded into the ALU stage
- Execute → Write Back: result · Computed value and status move to write-back
- Write Back → Register File: commit · Write-back updates the architectural register state
- Write Back → Fetch: next cycle · Completed instruction advances the sequential processor flow
- Processor Top → Testbench: observed by · Testbench monitors top-level outputs and internal progress
- Vivado Project → Processor Top: contains · Vivado project packages the RTL design
- Testbench → Waveforms: verified with · Waveform evidence documents expected simulation behavior
