Skip to content

AlanP13/Py8085-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

138 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sim8085 — 8085 Assembler + Simulator (lab-friendly)

sim8085 is a lightweight 8085-ish assembler + interactive simulator built to run classic microprocessor lab programs from this repo:

  • src/school/*.asm
  • src/personal/*.asm

It’s designed to be:

  • ✅ Easy to understand
  • ✅ Great for learning / teaching
  • ✅ Hackable and extendable
  • ✅ Perfect for running real 8085 lab sheets

This is an instruction-level simulator (not cycle-accurate). It focuses on executing the logic of programs correctly rather than emulating exact machine timings.


✨ Features

  • Interactive terminal REPL
  • Loads existing .asm templates from this repo
  • Label support (LOOP:, JNZ LOOP, etc.)
  • Simulated registers: A B C D E H L, SP, PC
  • Flags: S Z P CY
  • Full 64KB memory space
  • Breakpoints, stepping, memory inspection
  • Designed around real 8085 lab exercises

🚀 Quick Start

From the repo root:

python simulator/main.py

You should see:

8085>

🧪 Using the bundled .asm templates

List available templates:

8085> templates

Load a program by fuzzy-matching its filename:

8085> loadtpl school bubble

Seed memory:

8085> setmem 7050H 0AH

Run until HLT:

8085> run

Inspect registers:

8085> regs

Inspect memory:

8085> mem 7050H 40

🧠 Example: Bubble Sort Demo

Bubble sort expects:

  • 7050H = size
  • 7051H.. = array data

Example session:

8085> loadtpl school bubble
8085> setmem 7050H 0AH
8085> setmem 7051H 09H
8085> setmem 7052H 02H
8085> setmem 7053H 0AH
8085> setmem 7054H 01H
8085> setmem 7055H 07H
8085> setmem 7056H 03H
8085> setmem 7057H 08H
8085> setmem 7058H 04H
8085> setmem 7059H 06H
8085> setmem 705AH 05H
8085> run
8085> mem 7051H 0A

After running, memory block 7051H..705AH will be sorted.

🧾 REPL Commands

load <path>                 Load an .asm file
templates                   List available templates
loadtpl <school|personal> <name>
run [max_steps]             Run until HLT or breakpoint
step [n]                    Step instruction(s)
regs                        Show registers and flags
mem <addr> [len]            Dump memory
setmem <addr> <byte>        Write memory byte
bp <addr>                   Toggle breakpoint
bps                         List breakpoints
pc <addr>                   Set PC
reset                       Reset CPU and memory
help                        Show help
quit                        Exit

🧩 Supported Instruction Subset

Data movement

  • MOV, MVI, LXI
  • LDA, STA
  • LHLD, SHLD
  • LDAX, STAX
  • XCHG

Arithmetic / logic

  • `XRA, ADD, ADC, ADI
  • SUB, SBB, SUI
  • ANI, CMP, CPI
  • `INR, DCR
  • DAA, CMA

Rotate / flags

  • RRC, RAR, RLC
  • STC, CMC

16-bit / pointers

  • INX, DCX, DAD

Control flow

  • MP, JZ, JNZ, JC, JNC
  • CALL, RET
  • HLT

Assembler features

  • Labels (LOOP:)
  • ORG directive (optional, assembler-dependent)

🛠️ Extending the Simulator

Opcode execution lives in:

bash
simulator/sim8085/cpu.py

Add new instructions by extending the _exec() dispatcher. The assembler lives in:

bash
simulator/sim8085/assembler.py

🗂️ Project Structure

src/
  school/        # School lab programs
  personal/      # Personal practice programs

simulator/
  main.py        # Entry point
  sim8085/
    assembler.py # Parser / label resolver
    cpu.py       # CPU + memory + flags
    repl.py      # Interactive terminal
::contentReference[oaicite:0]{index=0}

About

Python-based 8085 instruction-level assembler and simulator with REPL, breakpoints, and memory inspection.

Resources

Stars

Watchers

Forks

Contributors