# maazm007/4_bit_signed_calculator architecture

> Architecture diagram of the GitHub repository maazm007/4_bit_signed_calculator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maazm007/4_bit_signed_calculator
- Repository: https://github.com/maazm007/4_bit_signed_calculator

## Overview

##### Project type and purpose
- This is not a software application but a digital‑hardware design targeting an FPGA (Xilinx ISE 14.7).
- It implements a 4‑bit signed “calculator” or mini‑ALU: it takes two 4‑bit operands (with sign bits), applies one of four arithmetic operations (add, subtract, multiply, divide), and produces a result.

##### File structure
- Top‑level directory:
- README.md (project description)
- “Xilinx Files”: generated netlists (.vf), symbol files (.sym), JHDL sources (.jhd), simulation artifacts (.wdb, .exe, .log), build scripts.
- “Xilinx Schematic Files”: the original schematic sources (.sch) that define each module’s internals.
- Key JHDL sources (.jhd) implement modules: Half_Adder, Full_Adder, Two’s_Complement, N‑bit Adders/Subtracters, Multiplier_4_Bit, Divider, MUXes, and the top‑level Adder_Calculator.jhd / Calculator.jhd.
- Simulation tree under “isim” shows how each module is instantiated and verified.

##### README
- Input pins: A[3:0], B[3:0], Sign_A, Sign_B, M1, M0
- Operation encoding on M1:M0
- Sign encoding on Sign_A:Sign_B for the two operands
- Four waveform screenshots demonstrating each operation

a. Main components (blocks):
- Input stage: two 4‑bit buses (A, B) plus two sign‑control pins (Sign_A, Sign_B)
- Sign‑extension units (Two’s_Complement blocks) for each operand – conditional invert & add‑one logic
- Arithmetic units:
– 4‑bit Adder module (built from Full_Adders)
– 4‑bit Subtracter module (similarly built, or via adder + two’s_complement)
– 4‑bit Multiplier block (Multiplier_4_Bit.jhd)
– 4‑bit Divider block (Divider.jhd)
- 4‑to‑1 Result multiplexer (Two_to_One_MUX and Four_to_One_MUX modules)
- Output bus (width depends on largest result—e.g., 8 bits for multiplication)
b. Relationships & interactions:
– Raw A, B feed into sign‑extension blocks, whose outputs are “signed” A′, B′.
– A′, B′ fan out to all four arithmetic units in parallel.
– Each arithmetic unit produces a candidate result.
– Control signals M1:M0 feed the top‑level multiplexer to select which unit’s output drives the final result bus.
c. Architectural patterns & principles:
– Data‑path / control‑path separation: sign‑extend + arithmetic blocks form the data‑path; M1, M0 form the control path.
– Hierarchical design: half‑adder → full‑adder → 4‑bit adder → ALU.
– Reusability: Two’s_Complement block reused for subtraction and sign handling.
d. Technologies & frameworks:
– JHDL (Java HDL) .jhd sources for RTL description, compiled into netlists (.vf) for Xilinx ISE.
– Xilinx schematic (.sch) files correspond one‑to‑one with JHDL modules, used for symbol generation (.sym).
– ISE simulator (.isim) artifacts for functional verification.

##### Detailed capturing of architectural elements
- Left zone: Sign‑extension (Two’s_Complement units) fed by raw inputs + Sign pins
- Center zone: Parallel arithmetic blocks (Adder, Subtractor, Multiplier, Divider) receiving the processed operands
- Right zone: 4‑to‑1 mux selecting final result based on M1:M0
- Beneath each block, annotate the source file names (e.g., “Multiplier_4_Bit.jhd / .sch”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Define nodes
    InputA["A[3:0]"]:::io
    InputB["B[3:0]"]:::io
    SignA["Sign_A"]:::control
    SignB["Sign_B"]:::control
    M1["M1"]:::control
    M0["M0"]:::control

    subgraph "Calculator Top" 
        direction TB
        subgraph "Sign-Extension Units" 
            direction TB
            TwosA["Two’s_Complement\n(.jhd/.sch)"]:::datapath
            TwosB["Two’s_Complement\n(.jhd/.sch)"]:::datapath
        end
        subgraph "Arithmetic Units" 
            direction TB
            Adder4["4-bit Adder\n(.jhd/.sch)"]:::datapath
            Sub4["4-bit Subtracter\n(.jhd/.sch)"]:::datapath
            Mult4["4-bit Multiplier\n(.jhd/.sch)"]:::datapath
            Div4["4-bit Divider\n(.jhd/.sch)"]:::datapath
        end
        subgraph "Result Selection" 
            direction TB
            Mux4to1["4-to-1 MUX\n(.jhd/.sch)"]:::datapath
        end
    end

    Output["Result Bus\n[7:0]"]:::io

    %% Connections: Inputs to sign-extension
    InputA --> TwosA
    SignA --- TwosA
    InputB --> TwosB
    SignB --- TwosB

    %% Sign-extended outputs to arithmetic
    TwosA --> Adder4
    TwosA --> Sub4
    TwosA --> Mult4
    TwosA --> Div4
    TwosB --> Adder4
    TwosB --> Sub4
    TwosB --> Mult4
    TwosB --> Div4

    %% Arithmetic outputs to mux
    Adder4 --> Mux4to1
    Sub4 --> Mux4to1
    Mult4 --> Mux4to1
    Div4 --> Mux4to1

    %% Control to mux
    M1 --- Mux4to1
    M0 --- Mux4to1

    %% Final output
    Mux4to1 --> Output

    %% Simulation and README
    README["Project README\n(README.md)"]:::info
    SimProj["Simulation Project\n(Calculator_beh.prj,\n/isim)"]:::info

    README -.-> CalcTop
    SimProj -.-> CalcTop

    %% Click events
    click Calculator_Top "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Calculator.jhd"
    click TwosA "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Twos_Complement.jhd"
    click TwosB "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Twos_Complement.jhd"
    click Adder4 "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Four_Bit_Adder.jhd"
    click Sub4 "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Subtracter_4_Bit.jhd"
    click Mult4 "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Multiplier_4_Bit.jhd"
    click Div4 "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Divider.jhd"
    click Mux4to1 "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Four_to_One_MUX.jhd"
    click README "https://github.com/maazm007/4_bit_signed_calculator/blob/main/README.md"
    click SimProj "https://github.com/maazm007/4_bit_signed_calculator/blob/main/Xilinx Files/Calculator_beh.prj"

    %% Styles
    classDef datapath fill:#CCE5FF,stroke:#004085,color:#004085;
    classDef control stroke-dasharray: 5 5,stroke:#FFA500,color:#FFA500;
    classDef io fill:#D4EDDA,stroke:#155724,color:#155724;
    classDef info fill:#E2E3E5,stroke:#6C757D,color:#6C757D;
```
