How programmingsis/simulador-de-processador works
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.