6502 Emulator
A software implementation of the MOS 6502 microprocessor written in Rust.
Overview
The goal of this project is to understand how CPUs execute instructions by implementing a 6502 emulator from scratch.
Unlike many simple emulators, this one aims to emulate individual instructions accurately while keeping the implementation clean and easy to understand.
Features
- 151 official instructions
- Multiple addressing modes
- Configurable memory bus
- Disassembler
- Debug logging
- Unit tests
Motivation
I wanted to better understand how processors execute instructions and how machine code interacts with memory.
This project also serves as preparation for building a small operating system and experimenting with computer architecture.
Architecture
+----------------+
| CPU |
+-------+--------+
|
+----------+----------+
| |
+-------v------+ +-------v------+
| Memory | | Registers |
+--------------+ +--------------+
Instruction Execution
Each instruction follows roughly the same flow:
- Fetch opcode.
- Decode instruction.
- Read operands.
- Execute.
- Update flags.
- Increment program counter.
Example
fn lda(&mut self, value: u8) {
self.a = value;
self.update_zero_and_negative_flags(self.a);
}
Current Progress
| Component | Status |
|---|---|
| CPU Registers | ✅ |
| Memory Bus | ✅ |
| Addressing Modes | 🚧 |
| Instructions | 🚧 |
| Interrupts | ❌ |
| Decimal Mode | ❌ |
Problems Encountered
The hardest part wasn't implementing instructions—it was realizing that several instructions behave differently depending on the addressing mode.
Another issue was understanding the processor status flags.
Lessons Learned
- Small abstractions make emulator code easier to extend.
- Writing tests early saves hours of debugging.
- Reading datasheets carefully is worth the effort.
Future Improvements
- Cycle accuracy
- Interrupt support
- Decimal mode
- Interactive debugger
- WebAssembly build
Screenshot

Related Lab Entries
- Understanding Zero Page Addressing
- Debugging ADC
- Implementing Status Flags
References
- MOS Technology 6502 Datasheet
- Programming the 65816
- NESDev Wiki
Source Code
GitHub:
https://github.com/Muhammed-Rajab
Demo: