A CPU and Assembly compiler written in Python
This project consists of a custom CPU, assembler, and runtime environment implemented in Python. The components include:
-
Instruction Set Architecture (ISA):
- Defined in
Drip.pyandQuadShot.py. - Instructions for arithmetic, jumps, data movement, comparison, stack operations, input/output, and subroutine calls.
- Defined in
-
Assembler:
- Implemented in
Drip.py. - Functions for tokenizing, parsing, and converting assembly code into machine code.
- Implemented in
-
CPU Runtime:
- Defined in
QuadShot.py. - Includes the
CPUclass with methods for executing instructions, managing registers, and handling input/output.
- Defined in
-
RAM:
- Defined in
ram.py. - Provides a simple interface for memory storage and retrieval.
- Defined in
-
Registers:
- Defined in
registers.py. - Manages the CPU registers, supporting single, double, and adjacent register operations.
- Defined in
Drip.py: Contains the ISA definition and assembler implementation.QuadShot.py: Contains the CPU runtime implementation.ram.py: Contains the RAM class for memory storage and retrieval.registers.py: Contains the Registers class for managing CPU registers.Grind.py: Contains the assembly pre-processor for Drip.BUBBLE2.drip: Example assembly code for a bubble sort algorithm.echo.drip: Example assembly code for an echo program.print.bean: Subroutine for printing strings.input.bean: Subroutine for reading input.
To run the CPU with an assembly program, use the following command:
python QuadShot.py <program_name> <input_string><program_name>: The name of the assembly program file (without the.dripextension).<input_string>: (Optional) Input string to be provided to the program.
Example:
python QuadShot.py BUBBLE2 "example input"This command will run the BUBBLE2.drip program with the input "example input".