This project is a simulator for a basic microprocessor, designed to help users understand the fundamental operations of a CPU. It includes a graphical user interface (GUI) for easy interaction and visualization of the processor's state.
You can find and download the executable file microprocessor-simulator.jar
from the root folder of this repository.
- Simulates basic microprocessor operations
- GUI for code input, execution, and state visualization
- Register display
- Memory visualization
- Supports basic assembly language instructions
- Java Development Kit (JDK) 8 or higher
- Java Swing library (typically included in JDK)
- Compile the Java files in the project.
- Run the
Main
class to start the simulator.
-
The main window consists of three panels:
- Code Editor (center)
- Registers (left)
- Memory (right)
-
Enter your assembly code in the Code Editor.
-
Click the "Run" button to execute the code.
-
The Register and Memory panels will update to show the current state of the processor.
-
Use the "Reset" button to clear the current state and start over.
The simulator supports the following instructions:
-
MVI
(Move Immediate): Loads an immediate value into a register- Example:
MVI A 02H
- Example:
-
MOV
(Move): Copies the content of one register to another- Example:
MOV B A
- Example:
-
ADD
: Adds the content of a register to the accumulator- Example:
ADD B
- Example:
-
SUB
: Subtracts the content of a register from the accumulator- Example:
SUB C
- Example:
-
LDA
(Load Accumulator): Loads the accumulator with the content of a memory location- Example:
LDA 2000H
- Example:
-
STA
(Store Accumulator): Stores the content of the accumulator in a memory location- Example:
STA 2008H
- Example:
-
HLT
(Halt): Stops the execution of the program- Example:
HLT
- Example:
Here's a sample program that demonstrates the use of these instructions:
MVI A 02H
MVI B 03H
SUB B
MVI C 05H
ADD C
STA 2008H
HLT
This program:
- Loads 02H into the accumulator
- Loads 03H into register B
- Subtracts B from A
- Loads 05H into register C
- Adds C to the accumulator
- Stores the result in memory location 2008H
- Halts the program
Main.java
: Entry point of the applicationCPU.java
: Central Processing Unit implementationGUI.java
: Graphical User InterfaceMemory.java
: Memory implementationRegister.java
: Register implementationFlagRegister.java
: Flag Register implementationInstructionExecutor.java
: Executes parsed instructionsInstructionParser.java
: Parses input instructionsInstruction.java
: Defines instruction structure and types