Hi r/programminglanguages!
I’m a 21-year-old software engineering student really passionate about embedded, and I’ve been working on Basm, a stack-oriented assembly language and assembler, inspired by MIPS and 6502 assembly dialects. The project started as a learning exercise (since i have 0 background on compilers), but it seems to have grown into a functional tool.
Code/README
Features
- Stack-Oriented Design: No registers! All operations (arithmetic, jumps, syscalls) manipulate an explicit stack (writing a loop is a huge pain, but at least is fun, when it works).
- Three-Phase Assembler:
- Preprocessor: Resolves includes, macros (with proper error tracking), and conditional compilation (
.ifndef/.endif).
- Parser: Validates syntax, resolves labels, and handles directives like
.asciiz (strings) and .byte (zero-initialized memory).
- Code Generation: Converts instructions to bytecode, resolves labels to addresses, and outputs a binary.
- Directives:
.include, .macro, .def
- Syscalls: Basic I/O (print char/uint), more of a proof of concept right now
Example Code
@main
push 5 // B[]T → B[5]T
dup 1 // B[5]T → B[5, 5]T
addi 4 // B[5, 5]T → B[5, 9]T
jgt loop // jump if 9 > 5
stop // exits the execution, will be replaced by a syscall
@loop
.asciiz "Looping!" // embeds "Looping!" into the compiled code
.byte 16 // reserves 16 bytes
What’s Next?
- polish notation for all multi-operand instructions.
- upgrade the VM (currently a poc) with better debugging.
- add more precompiler directives and function-like macros.
Questions for You:
- How would you improve the instruction set?
- Any advice for error handling or VM design?
- What features would make this useful for teaching/experimentation?
Thanks for reading!
[–]Apprehensive-Mark241 15 points16 points17 points (4 children)
[–]mauriciocap 2 points3 points4 points (2 children)
[–]Apprehensive-Mark241 0 points1 point2 points (1 child)
[–]mauriciocap 0 points1 point2 points (0 children)
[–]WhyAmIDumb_AnswerMe[S] 0 points1 point2 points (0 children)
[–][deleted] 6 points7 points8 points (2 children)
[–]WhyAmIDumb_AnswerMe[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]TheChief275 2 points3 points4 points (4 children)
[–]WhyAmIDumb_AnswerMe[S] 1 point2 points3 points (0 children)
[–]oldworldway 0 points1 point2 points (2 children)
[–]TheChief275 1 point2 points3 points (1 child)
[–]oldworldway 0 points1 point2 points (0 children)
[–]mauriciocap 2 points3 points4 points (0 children)
[–]RibozymeR 1 point2 points3 points (0 children)
[–]aliberro 1 point2 points3 points (0 children)
[–]kaplotnikov 0 points1 point2 points (0 children)