Tiny8: An Educational 8-bit CPU Simulator with Interactive Visualization
This repository profile is provided by osrepos.com, an open source repository discovery platform.

Summary
Tiny8 is a lightweight and educational 8-bit CPU simulator written in Python. It offers an interactive terminal debugger and graphical animation to visualize program execution, making it ideal for learning computer architecture and assembly programming.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
Tiny8 is a powerful and educational 8-bit CPU simulator, meticulously crafted in Python. Designed to demystify computer architecture, it provides a hands-on environment for exploring assembly programming and real-time visualization of CPU operations. Inspired by AVR architecture, Tiny8 features a robust 8-bit CPU with 32 general-purpose registers, a comprehensive instruction set, and advanced debugging tools, all without heavy dependencies.
Key features include an interactive terminal debugger with Vim-style navigation, change highlighting, and advanced search capabilities. For visual learners and educators, Tiny8 can generate high-quality GIF/MP4 animations of program execution, illustrating register evolution, memory access patterns, and flag changes. This makes it an excellent tool for understanding how programs interact with hardware at a fundamental level.
Real-time visualization of a bubble sort algorithm executing on Tiny8
Installation
Getting started with Tiny8 is straightforward. You can install it directly using pip:
pip install tiny8
Examples
Tiny8 comes with a variety of examples to help you understand its capabilities. Let's look at a simple Fibonacci sequence calculator.
First, create an assembly file, fibonacci.asm:
; Fibonacci Sequence Calculator
; Calculates the 10th Fibonacci number (F(10) = 55)
; F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2)
;
; Results stored in registers:
; R16 and R17 hold the two most recent Fibonacci numbers
ldi r16, 0 ; F(0) = 0
ldi r17, 1 ; F(1) = 1
ldi r18, 9 ; Counter: 9 more iterations to reach F(10)
loop:
add r16, r17 ; F(n) = F(n-1) + F(n-2)
mov r19, r16 ; Save result temporarily
mov r16, r17 ; Shift: previous = current
mov r17, r19 ; Shift: current = new result
dec r18 ; Decrement counter
brne loop ; Continue if counter != 0
done:
jmp done ; Infinite loop at end
Then, run it using the Tiny8 CLI. You can either use the interactive debugger or generate an animation:
tiny8 fibonacci.asm # Interactive debugger
tiny8 fibonacci.asm -m ani -o fibonacci.gif # Generate animation
Tiny8 also provides a Python API for integrating the simulator into your own scripts:
from tiny8 import CPU, assemble_file
asm = assemble_file("fibonacci.asm")
cpu = CPU()
cpu.load_program(asm)
cpu.run(max_steps=1000)
print(f"Result: R17 = {cpu.read_reg(17)}") # Final Fibonacci number
Why Use Tiny8?
Tiny8 serves various audiences with its unique blend of simplicity and power:
- For Students: It offers an unparalleled opportunity to write assembly code and observe immediate, visual feedback. Students can understand precisely how each instruction impacts the CPU state, free from high-level abstractions.
- For Educators: Tiny8 facilitates interactive demonstrations, simplifies the creation of assembly programming assignments, and allows for the generation of engaging animations for lectures and teaching materials.
- For Hobbyists: It provides a platform for rapid algorithm prototyping at the hardware level. With minimal overhead and an extensible, readable Python codebase, hobbyists can experiment with low-level programming concepts efficiently.
Links
For more detailed information, documentation, and community engagement, please refer to the official resources:
- Official Documentation: sql-hkr.github.io/tiny8
- GitHub Repository: sql-hkr/tiny8
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Source repository
Open the original repository on GitHub.