sapcpu
Version, currently 0.1.45 versions
github.com/SleepingInsomniac/sapcpu
BE-SAP1 8bit CPU emulator
5 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
sapcpu:
github: SleepingInsomniac/sapcpu
version: ~> 0.1.4Then run:
shards installshard.yml
- Crystal
1.4.0- License
- MIT
- Author
- Alex Clink
- Target
sapcpufrom src/cli.cr
Dependencies
This version declares no dependencies.
README
SAP 8-bit CPU Emulator
Emulates a version of the "Simple As Possible" 8-bit CPU
Installation
macOS
- Install crystal:
brew install crystal - build the program:
shards build --release
The build will be placed in bin
CLI Usage
Build a program:
$ sapcpu build examples/multiply.asm -o a.out
Run a program:
$ sapcpu run examples/multiply.eat
Run and build a program:
$ sapcpu run examples/multiply.asm -a
Usage: sapcpu [arguments]
-v, --verbose Run verbosely
build assemble a file
dasm dis-assemble a binary
run run a program
-h, --help Show this help
Usage: sapcpu build [arguments]
-v, --verbose Run verbosely
-h, --help Show this help
-o NAME Output file name
Usage: sapcpu dasm [arguments]
-v, --verbose Run verbosely
-h, --help Show this help
Usage: sapcpu run [arguments]
-v, --verbose Run verbosely
-h, --help Show this help
-a, --asm Assemble before running
-g, --gui Run with a gui
-d DELAY, --delay DELAY Add a delay to each clock pulse (s)
Instructions
NOP - No-op
LDA - Load A
ADD - Add A with memory
SUB - Subtract A with memory
STA - Store A to memory
LDI - Load Immediate to A
JMP - Jump to Immediate
JC - Jump on Carry
JZ - Jump on Zero
ADI - Add immediate
OUT - Output (Prints to STDOUT)
HLT - Halt execution (Exits the emulator)
CPU Layout
Bus
Memory Address ●●●●●●●● Prog Counter RAM
●●●● ⫦-------⫣ ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●● 00: 00000000
$00 ⎪⎪⎪⎪⎪⎪⎪⎪ $00 01: 00000000
Memory Contents ⎪⎪⎪⎪⎪⎪⎪⎪ A Register 02: 00000000
●●●●●●●● ⫦-------⫣ ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●● 03: 00000000
$00 ⎪⎪⎪⎪⎪⎪⎪⎪ 000 04: 00000000
Instruction ⎪⎪⎪⎪⎪⎪⎪⎪ Sum Register 05: 00000000
●●●●●●●● ⫦-------⫣ ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●● 06: 00000000
HLT ⎪⎪⎪⎪⎪⎪⎪⎪ 000 07: 00000000
Flags MC Step ⎪⎪⎪⎪⎪⎪⎪⎪ B Register 08: 00000000
●● ●●● ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●●
ZC ⎪⎪⎪⎪⎪⎪⎪⎪ 000
Control Word ⎪⎪⎪⎪⎪⎪⎪⎪ Output
●●●●●●●●●●●●●●●●●● ⎪⎪⎪⎪⎪⎪⎪⎪ ⫦-------⫣ ●●●●●●●●
JJFJCCOBSEAAIIRRMH 000
ZCI OEIIUOOIIOOIIL
T
Contributors
- Alex Clink - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.4- Tagged
- Apr 24, 2022
- Commit
5febcd94ef83- Crystal
1.4.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/SleepingInsomniac/sapcpu
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 5