https://github.com/knightchaser/knightzcpu
A small and simple CPU simulation code. (Writing code when I have some time)
https://github.com/knightchaser/knightzcpu
Last synced: 9 months ago
JSON representation
A small and simple CPU simulation code. (Writing code when I have some time)
- Host: GitHub
- URL: https://github.com/knightchaser/knightzcpu
- Owner: KnightChaser
- Created: 2024-04-19T12:56:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-19T14:16:08.000Z (about 2 years ago)
- Last Synced: 2025-03-23T10:25:43.516Z (about 1 year ago)
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# knightzcpu
> A simple **CPU** simulation on C++
This Simple CPU Simulator **will be** (is) designed as an educational tool for computer engineering students to understand the basic workings of a CPU. This project is implemented in C++, and it simulates the essential operations of a CPU, including fetching, decoding, and executing instructions. It is kept deliberately simple to make it fun and accessible while providing substantial learning opportunities.
## Todos
- **Basic CPU Operations**: Simulate the fetch, decode, and execute cycles of a CPU.
- **Registers and Memory**:
- Registers: Accumulator (A), Index Register (X), Stack Pointer (SP), and Program Counter (PC), etc.
- 256n bytes of memory, etc.
- **Status Flags**: Carry (C), Zero (Z), Interrupt Disable (I), Decimal Mode (D), Break Command (B), Overflow (V), and Negative (N).
- **Interactive Input**: Users can input instructions or programs via the console or by loading files.
- **Visual Output**: The state of the CPU (registers, memory, flags) can be printed out after each cycle for educational purposes.
## Components
### Classes
- **CPU Class**: Encapsulates all operations of the simulated CPU, including the execution cycle.
- **Memory Class**: Manages operations related to memory access.
### Main Functions
- **fetch()**: Retrieves an instruction from memory based on the current value of the Program Counter (PC).
- **decode(uint8_t instruction)**: Identifies the operation to be performed based on the fetched instruction.
- **execute()**: Executes the decoded instruction.
- **run()**: Initiates and controls the execution cycle until a halt condition is met.