A tiny CPU simulator written in Python
GitHub Repo

A tiny CPU simulator written in Python

@the_ospsPost Author

Project Description

View on GitHub

A Tiny CPU Simulator in Python: See How Your Code Really Runs

Ever wonder what's actually happening inside your CPU when your code executes? We're always working at a high level of abstraction, but sometimes it's fascinating to peek beneath the hood. That's where tiny8 comes in—a minimal but surprisingly capable CPU simulator written in pure Python.

This isn't just another toy project. It's a clean, readable implementation that demonstrates fundamental computing concepts in a way that's actually accessible. Whether you're a student trying to understand computer architecture or a curious developer wanting to see how instructions get processed, tiny8 offers a perfect window into the machine.

What It Does

Tiny8 simulates an 8-bit CPU with a straightforward architecture. It includes the essential components you'd find in a real processor: registers for temporary data storage, an ALU (Arithmetic Logic Unit) for mathematical operations, and program memory that stores instructions. The simulator reads assembly-like instructions and executes them step-by-step, showing you exactly how data moves through the system and gets transformed along the way.

The project implements a simple instruction set covering the basics—data movement between registers, arithmetic operations like addition and subtraction, and program control flow through jumps. It's intentionally minimal, which makes it much easier to understand than complex modern processors.

Why It's Cool

The beauty of tiny8 lies in its simplicity and clarity. Since it's written in clean Python code, you can actually read through the entire implementation and understand how each component works. The cpu.py file is particularly well-structured—you can see the fetch-decode-execute cycle happening in real code, not just theory.

This makes it incredibly valuable for learning. You can write small programs in the custom assembly language and watch how each instruction affects the CPU state. Want to see how a loop works at the hardware level? Or how data gets processed through multiple operations? You can trace through everything step by step.

It's also hackable. The codebase is small enough that you can easily modify it—maybe add new instructions, change the architecture, or implement different addressing modes. It's a perfect sandbox for experimenting with computer architecture concepts without needing specialized hardware or complex toolchains.

How to Try It

Getting started takes just a few minutes. Clone the repository and run the simulator with a sample program:

git clone https://github.com/sql-hkr/tiny8
cd tiny8
python cpu.py

The repository includes example programs that demonstrate what the CPU can do. You can also write your own programs using the simple assembly language—the README documents the available instructions and how to use them.

For a quick taste, check out the example code in the repository. You'll see how to load values into registers, perform calculations, and control program flow. It's surprisingly satisfying to watch your code execute at this fundamental level.

Final Thoughts

Tiny8 hits that sweet spot between educational and genuinely interesting. It's not trying to be a production tool, but as a learning resource and experimentation platform, it's incredibly effective. I could see this being useful for computer science students, developers curious about low-level programming, or anyone who wants to understand what's really happening when their Python code runs.

The fact that it's implemented in Python makes it accessible to a wide audience, and the clean code means you can focus on the concepts rather than fighting with the implementation. It's the kind of project that reminds us why understanding fundamentals matters—even when we spend most of our time working with high-level abstractions.

@githubprojects

Back to Projects
Project ID: 1982815901280845849Last updated: October 27, 2025 at 02:25 PM