This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MPU (Memory Processing Unit) is a 16-bit virtual computer system written in Go. It includes:
- A complete virtual machine with no general-purpose registers (all operations on memory)
- An assembler for MPU assembly language
- SDL-based graphics and audio support
- Example programs including games (pong, blocks) and demos
# Install dependencies (macOS)
brew install sdl2{,_image,_mixer,_ttf,_gfx} pkg-config
# Install dependencies (Ubuntu)
apt install pkg-config build-essential libsdl2{,-image,-mixer,-ttf,-gfx}-dev
# Build the project
go build# Run an assembly program directly
./mpu run example/hello.s
# Run with monitor/debugger mode
./mpu run -m example/hello.s
# Compile assembly to binary
./mpu build -o output.bin input.s
# Format assembly source
./mpu fmt input.s# Run all tests
go test ./...
# Run tests in a specific package
go test ./asm
go test ./machine
# Run tests with verbose output
go test -v ./...
# Run a specific test
go test -run TestParseLineNumbers ./asm-
/asm- Assembler implementationlexer.go- Tokenizes assembly source filesparser.go- Parses tokens into AST statementslinker.go- Links and generates machine codeprinter.go- Formats assembly sourcesymbols.go- Symbol table management
-
/machine- Virtual machine implementationmachine.go- Core CPU emulation and instruction executionmemory.go- 64KB memory managementencoding.go- Instruction encoding/decodingio.go- Peripheral Management Interface (PMI)graphics.go- SDL graphics adapterstdout.go- Standard output devicerng.go- Random number generator
-
Memory-Mapped Architecture: No general-purpose registers; PC, SP, and FP are at memory addresses 0x00-0x05
-
Variable-Length Instructions: Opcodes are 1 byte, followed by 0-4 bytes depending on addressing mode
-
PMI (Peripheral Management Interface): All I/O goes through memory addresses 0x06 (request) and 0x08 (status)
-
Two-Pass Assembly: Parser creates AST, then linker resolves symbols and generates code
-
Addressing Modes: Immediate (#), Absolute (a), Indirect (*), Relative (r), and combinations
- Standard Go testing with
*_test.gofiles - Uses
github.com/stretchr/testifyfor assertions - Parser tests verify AST construction
- Machine tests verify instruction execution
- Memory tests verify read/write operations
/machine/machine.go- Core CPU implementation/asm/parser.go- Assembly language syntax/example/hello.s- Simple assembly example/example/stdlib/stdio.s- Standard library implementation