- Problem Statement
- Solution
- Run Instructions
- Code Structure
- Expected Outputs
In the realm of computer architecture, simulating a processor design is essential for understanding its performance and behavior under various conditions. The challenge was to develop a software-based CPU simulator capable of accurately processing instructions according to the TOY-RISC architecture. This involved implementing a 5-staged pipelined processor with robust handling of data and branch interlocks to ensure precise execution.
This project addresses the problem by creating a highly efficient CPU simulator in Java, focusing on the TOY-RISC architecture. Key features include:
- 5-Staged Pipelined Processor: Implemented a pipelined processor model with stages including Instruction Fetch (IF), Operand Fetch (OF), Execute (EX), Memory Access (MA), and Register Write (RW).
- Latches for Pipeline: Utilized various latch types (e.g., IF_OF_LatchType, OF_EX_LatchType) to manage data flow between pipeline stages, ensuring smooth and efficient operation.
- Handling Interlocks: Implemented mechanisms to handle data hazards and branch hazards using sophisticated control units (e.g., Z_BranchControlUnit, Z_DataControlUnit), ensuring 100% accurate execution of instructions.
- Configurable Simulation: Provided flexibility through a configuration file (
config.xml
) to define processor parameters and behavior.
To run the CPU simulator:
- Build the JAR file:
ant make-jar
- Execute the JAR file with the following arguments:
java -jar <path-to-jar-file> <path-to-config-file> <path-to-stat-file> <path-to-object-file>
- : Path to the generated JAR file in the /jars folder.
- : Path to the config.xml file located in /src/Configuration.
- and : Paths where output statistics and object file results will be saved.
The project is organized into several packages and classes:
Contains classes related to configuration management:
- Configuration.java: Handles loading and parsing of the config.xml file.
Contains generic utility classes and core simulation components:
- Instruction.java, Misc.java, Operand.java: Classes for defining and managing instructions and operands.
- Simulator.java: Main class for initializing and running the CPU simulator.
- Statistics.java: Collects and manages statistics during simulation.
Contains the main entry point of the application:
- main.java: Entry point for starting the CPU simulation.
Contains classes related to the CPU and its components:
- MainMemory.java: Simulates the main memory of the processor.
Latch type for managing data flow between Execute (EX) and Instruction Fetch (IF) stages.
Latch type for managing data flow between Execute (EX) and Memory Access (MA) stages.
Implements the Execute (EX) stage of the pipeline.
Latch type for managing data flow between Instruction Fetch (IF) and Enable stages.
Latch type for managing data flow between Instruction Fetch (IF) and Operand Fetch (OF) stages.
Implements the Instruction Fetch (IF) stage of the pipeline.
Latch type for managing data flow between Memory Access (MA) and Register Write (RW) stages.
Implements the Memory Access (MA) stage of the pipeline.
Latch type for managing data flow between Operand Fetch (OF) and Execute (EX) stages.
Implements the Operand Fetch (OF) stage of the pipeline.
Manages the register file operations.
Implements the Register Write (RW) stage of the pipeline.
Control unit for managing branch hazards.
Control unit for managing data hazards.
These files collectively define the structure and behavior of the pipelined processor in the CPU simulator, ensuring efficient and accurate execution of instructions.
After executing the CPU simulator with the provided inputs, you can expect the following outputs:
- Hash of the Processor State:
- Number of instructions executed:
- Number of cycles taken:
- Number of wrong branches taken:
- Number of wrong instructions entered pipeline for wrong branches:
- Number of halts: