Modern Assembly Language Inspired by Machine W Architecture
______ __
/\ _ \ /\ \
\ \ \_\ \ ____ ___ ___ ___ \_\ \ __ __ __ ____
\ \ __ \ /',__\ /' __` __`\ / __`\ /'_` \ /'__`\/\ \/\ \ /',__\
\ \ \/\ \/\__, `\/\ \/\ \/\ \/\ \_\ \/\ \_\ \/\ __/\ \ \_\ \/\__, `\
\ \_\ \_\/\____/\ \_\ \_\ \_\ \____/\ \___,_\ \____\\ \____/\/\____/
\/_/\/_/\/___/ \/_/\/_/\/_/\/___/ \/__,_ /\/____/ \/___/ \/___/
Asmodeus is a complete assembly language toolchain inspired by the legendary Machine W architecture. It features a full compiler pipeline from source code to executable machine code, with advanced debugging capabilities and an extensible instruction set.
- Complete Toolchain: Lexer → Parser → Assembler → Virtual Machine
- Machine W Architecture: 16-bit word size, 2048 words of memory
- Extended Instruction Set: Advanced arithmetic operations (MNO, DZI, MOD)
- Interactive Debugger: Bugseer - step-by-step execution with breakpoints
- Real-time I/O: Character-based input/output for interactive programs
- Multiple Addressing Modes: Direct, immediate, indirect, register-based
- Macro System: Define reusable code blocks with parameters
- Label Resolution: Forward and backward references
- Error Diagnostics: Comprehensive error reporting with line numbers
- Binary Disassembly: Convert machine code back to readable assembly
- Verbose Debugging: Detailed execution tracing and state inspection
curl -sSL https://raw.githubusercontent.com/szymonwilczek/asmodeus/main/installers/install.sh | bash- Clone the repository:
git clone https://github.com/szymonwilczek/asmodeus.git
cd asmodeus- Build and install:
cargo build --release
cp target/release/asmodeus ~/.local/bin/asmod- Add to PATH (add to ~/.bashrc or ~/.zshrc):
export PATH="$HOME/.local/bin:$PATH"git clone https://github.com/szymonwilczek/asmodeus.git
cd asmodeus
cargo build
# Use cargo run -- [args] or ./installers/dev.sh [args] for developmentCreate hello.asmod:
; Simple hello world program
start:
POB message ; Load message value into accumulator
WYJSCIE ; Output the value
STP ; Stop program
message: RST 42 ; Our "hello world" message (42)Run it:
asmod run hello.asmod; Add two numbers
start:
POB first ; Load first number
DOD second ; Add second number
WYJSCIE ; Output result
STP ; Stop
first: RST 25 ; First operand
second: RST 17 ; Second operand; Calculate (15 * 3) / 5 = 9
start:
POB #15 ; Load immediate value 15
MNO #3 ; Multiply by 3 (extended instruction)
DZI #5 ; Divide by 5 (extended instruction)
WYJSCIE ; Output result (9)
STP
; Run with: asmod run --extended program.asmod# Run assembly program (default mode)
asmod run program.asmod
asmod program.asmod # Same as above
# Assemble to binary without running
asmod assemble program.asmod -o program.bin
# Disassemble binary back to assembly
asmod disassemble program.bin
# Interactive debugger with breakpoints
asmod debug program.asmod
# Real-time character I/O mode
asmod interactive program.asmod
# Enable extended instruction set
asmod run --extended program.asmod
# Verbose output for debugging
asmod run --verbose --debug program.asmod-o, --output FILE: Specify output file-v, --verbose: Verbose output during compilation and execution--debug: Enable debug output (tokens, AST, etc.)-e, --extended: Enable extended instruction set (MNO, DZI, MOD)-h, --help: Show help message
Asmodeus emulates the Machine W architecture with:
- Memory: 2048 words of 16-bit memory (addresses 0-2047)
- Registers:
AK- Accumulator (16-bit)L- Instruction counter (11-bit, 0-2047)AD- Address register (11-bit)KOD- Opcode register (5-bit)WS- Stack pointer (11-bit, grows downward from 2047)R0-R7- General purpose registers (16-bit each)
DOD addr- Add memory[addr] to AKODE addr- Subtract memory[addr] from AKDOD #value- Add immediate value to AKODE #value- Subtract immediate value from AK
ŁAD addr/LAD addr- Store AK to memory[addr]POB addr- Load memory[addr] to AKPOB #value- Load immediate value to AK
SOB addr- Unconditional jump to addrSOM addr- Jump to addr if AK < 0SOZ addr- Jump to addr if AK = 0STP- Stop program execution
SDP- Push AK to stackPZS- Pop from stack to AK
WEJSCIE/WPR- Read input to AKWYJSCIE/WYJ- Output AK value
DNS- Disable interruptsCZM- Clear interrupt maskMSK- Set interrupt maskPWR- Return from interrupt
Enable with --extended flag:
MNO addr- Multiply AK by memory[addr]DZI addr- Divide AK by memory[addr]MOD addr- AK = AK % memory[addr]MNO #value- Multiply AK by immediate valueDZI #value- Divide AK by immediate valueMOD #value- AK = AK % immediate value
- Direct:
POB 100- Use memory[100] - Immediate:
POB #42- Use literal value 42 - Indirect:
POB [100]- Use memory[memory[100]] - Register:
POB R1- Use register R1 value - Register Indirect:
POB [R1]- Use memory[R1]
RST value- Reserve memory and initialize with valueRPA- Reserve memory without initialization (0)
MAKRO macro_name param1 param2
; macro body
DOD param1
SOB param2
KONM
; Usage
start:
macro_name 100 end_label; Line comment
// C-style comment
label_name: ; Define label
POB data ; Reference label
SOB label_name
data: RST 42Asmodeus includes Bugseer, a powerful interactive debugger:
asmod debug program.asmods/step- Execute single instructionc/continue- Continue execution until breakpoint or endd/display- Show current machine stateb ADDRESS/breakpoint ADDRESS- Set breakpoint at addressrb ADDRESS- Remove breakpointlb- List all breakpointsm START [END]- Dump memory rangeh/help- Show all commandsq/quit- Exit debugger
(bugseer)> b 5 # Set breakpoint at address 5
(bugseer)> c # Continue until breakpoint
(bugseer)> d # Display machine state
(bugseer)> m 0 10 # Show memory 0-10
(bugseer)> s # Step one instruction
The Asmodeus toolchain consists of several interconnected crates:
asmodeus/
├── src/ # Main CLI application
├── lexariel/ # Lexical analyzer (tokenizer)
├── parseid/ # Parser (tokens → AST)
├── hephasm/ # Assembler (AST → machine code)
├── asmachina/ # Virtual machine (Machine W emulator)
├── dismael/ # Disassembler (machine code → assembly)
├── shared/ # Shared types and utilities
├── examples/ # Example programs
│ ├── basic/ # Simple examples
│ ├── arithmetic/ # Math operations
│ ├── extended_set/ # Extended instruction examples
│ ├── io/ # Input/output examples
│ └── errors/ # Error demonstration
└── tests/ # Integration tests
Source Code (.asmod)
↓ [Lexariel]
Tokens
↓ [Parseid]
Abstract Syntax Tree (AST)
↓ [Hephasm]
Machine Code
↓ [Asmachina]
Execution Results
; Calculate 5! = 120
start:
POB one ; result = 1
LAD result
POB n ; counter = 5
LAD counter
loop:
POB counter ; if counter == 0, done
SOZ done
POB result ; result *= counter
MNO counter ; (requires --extended)
LAD result
POB counter ; counter--
ODE one
LAD counter
SOB loop
done:
POB result ; output result
WYJSCIE
STP
n: RST 5
one: RST 1
result: RPA
counter: RPA; Echo program with real-time I/O
start:
WEJSCIE ; Read character
WYJSCIE ; Echo it back
STP
; Run with: asmod interactive echo.asmod; Demonstrate stack usage
start:
POB #10 ; Push 10 to stack
SDP
POB #20 ; Push 20 to stack
SDP
PZS ; Pop 20 to AK
WYJSCIE ; Output 20
PZS ; Pop 10 to AK
WYJSCIE ; Output 10
STPFor more examples, checkout examples directory
git clone https://github.com/szymonwilczek/asmodeus.git
cd asmodeus
cargo build --release# Unit tests
cargo test
# Integration tests
cargo test --test integration
# Test specific crate
cargo test -p lexariel
cargo test -p asmachina# Use development wrapper
./installers/dev.sh run examples/basic/hello.asmod
# Or use cargo directly
cargo run -- run examples/basic/hello.asmod- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
lexariel/- Lexical analysis and tokenizationparseid/- Syntax analysis and AST generationhephasm/- Assembly and code generationasmachina/- Virtual machine and executiondismael/- Disassembly and reverse engineeringshared/- Common types and utilities
Extended instructions not working
# Make sure to use --extended flag
asmod run --extended program.asmodFile extension errors
# Use .asmod for source files
asmod run program.asmod
# Use .bin for binary files (warning: binary files should contain valid Asmodeus syntax!)
asmod disassemble program.binDivision by zero error
# Check for DZI or MOD with zero operand
DZI #0 ; This will cause runtime errorUndefined symbol error
# Make sure all labels are defined
POB undefined_label ; Error: symbol not foundasmod --help # Show all options
asmod debug program.asmod # Use interactive debugger
asmod run --verbose program.asmod # Verbose outputThis project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the classic Machine W architecture
- Built with modern Rust for performance and safety
- Designed for educational purposes and assembly language learning
Made with ❤️ for assembly language enthusiasts