# programmingsis/simulador-de-processador architecture

> Architecture diagram of the GitHub repository programmingsis/simulador-de-processador, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/programmingsis/simulador-de-processador
- Repository: https://github.com/programmingsis/simulador-de-processador

## Overview

##### Project type and purpose
- This is a standalone C-based processor simulator (an educational/simple CPU emulator).
- It reads hexadecimal op-codes from “teste.txt,” decodes them into instructions, executes arithmetic, logical, and control operations, and halts when it sees a HALT opcode.
- The Makefile automates compilation (`make build`) and execution (`make run`).

##### File structure
- EP1.c: core simulator implementation (instruction fetch, decode, execute).
- driverEP1.c / driverEP1.h: top-level driver, CLI or file I/O routines for loading “teste.txt” and invoking the simulator.
- teste.txt: sample program (hex codes).
- Makefile: build and run scripts.
- README.md: project description and usage.

##### Key insights from the README
- Supported operations: ADD, SUB, AND, OR, XOR, NOT, ZERO/ONE fill, JUMP, RETURN, HALT.
- Emphasis on simple CPU instruction set and an automated build/test flow.

##### Main components
a. Input Loader (driverEP1)
- Reads “teste.txt”
- Converts hex codes into an instruction memory buffer
b. Instruction Fetch & Decode Unit (EP1)
- Program Counter (PC)
- Instruction Register (IR)
- Opcode Decoder
c. Execution Unit (EP1)
- Arithmetic Logic Unit (ALU) for ADD, SUB, AND, OR, XOR, NOT
- Special Operations Handler for ZERO, ONE, JUMP, RETURN, HALT
d. Register File (EP1)
- Small set of general-purpose registers
- Support for read/write by the ALU and control logic
e. Control Unit (EP1)
- Updates PC for sequential flow, jumps, returns
- Manages HALT flag
f. Output / Logger (driverEP1)
- Prints register states or memory dump after execution
g. Build System (Makefile)
- Targets: build (compilation), run (compile + execute)

##### Relationships and data flows
- DriverEP1 → Input Loader → Instruction Memory
Instruction Memory → Fetch & Decode → Control Unit & ALU → Register File
Control Unit → PC updates / HALT signal → stops fetch loop
After HALT → DriverEP1 → Output Logger
- Makefile wraps `gcc driverEP1.c EP1.c` into a binary and then invokes it

##### Architectural patterns / design principles
- Modular separation: I/O (driver) vs. core logic (EP1).
- Single-pass fetch-decode-execute loop (classic Von Neumann cycle).
- Clear separation of concerns: decoding, execution, control, and I/O.

##### Relevant technologies / libraries
- Language: C99 (standard library for file I/O, stdio.h).
- Build: GNU Make.

##### Diagramming conventions
- Rectangles: modules/subsystems
- Notes or small text blocks: supported operations and special instructions

##### Final advice
- Be exhaustive: show every C module and its responsibility.
- Von Neumann cycle clearly (Fetch → Decode → Execute → Writeback → Next PC).
- Test harness (driverEP1 + teste.txt) and the Makefile’s role as an external service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "I/O Modules"
        Loader["Input Loader"]:::io
        Output["Output / Logger"]:::io
    end

    subgraph "Core CPU Logic"
        FD["Fetch & Decode Unit"]:::cpu
        EX["Execution Unit"]:::cpu
        RF["Register File"]:::cpu
        CU["Control Unit"]:::cpu
    end

    InstrMem["Instruction Memory\nteste.txt"]:::storage

    subgraph "Build System"
        Make["Makefile"]:::build
        Doc["README.md"]:::build
    end

    %% Data and control flows
    Loader -->|"loads hex codes"| InstrMem
    InstrMem -->|"fetch instruction"| FD
    FD -->|"decoded opcode"| EX
    FD -->|"control signals"| CU
    EX -->|"ALU operations"| RF
    RF -->|"read/write registers"| EX
    CU -->|"update PC / HALT"| FD
    CU -->|"HALT detected"| Output
    Output -->|"prints state"| Loader

    Make -->|"build & run"| Loader
    Doc -.->|"project description"| Loader

    %% Click events
    click Loader "https://github.com/programmingsis/simulador-de-processador/blob/main/driverEP1.c"
    click Output "https://github.com/programmingsis/simulador-de-processador/blob/main/driverEP1.c"
    click FD "https://github.com/programmingsis/simulador-de-processador/blob/main/EP1.c"
    click EX "https://github.com/programmingsis/simulador-de-processador/blob/main/EP1.c"
    click RF "https://github.com/programmingsis/simulador-de-processador/blob/main/EP1.c"
    click CU "https://github.com/programmingsis/simulador-de-processador/blob/main/EP1.c"
    click InstrMem "https://github.com/programmingsis/simulador-de-processador/blob/main/teste.txt"
    click Make "https://github.com/programmingsis/simulador-de-processador/tree/main/Makefile"
    click Doc "https://github.com/programmingsis/simulador-de-processador/blob/main/README.md"

    %% Styles
    classDef io fill:#d4f5d4,stroke:#4caf50,stroke-width:2px
    classDef cpu fill:#d4e3f7,stroke:#2196f3,stroke-width:2px
    classDef storage fill:#f7f1d4,stroke:#fbc02d,stroke-width:2px,stroke-dasharray: 5 5
    classDef build fill:#e0e0e0,stroke:#9e9e9e,stroke-width:2px
```
