Skip to content

EmbeddedAndroid/malbolge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Malbolge: interpreter, compilers, and an RTOS on an STM32U585

Malbolge is an esoteric language designed to be almost impossible to program — every instruction is encrypted after it runs, opcodes depend on the program counter's position, and the two data operations are deliberately obtuse. This repo takes it all the way from a faithful interpreter to a cooperative RTOS whose tasks are Malbolge programs, running bare-metal on a microcontroller and scrolling text on an LED matrix.

What's here

interpreter/ — interpreter + compilers (Python)

  • malbolge.py — a faithful interpreter, a line-for-line reimplementation of Ben Olmstead's 1998 reference C, validated differentially against that reference (~21k checks: hundreds of cat inputs + 20k fuzzed programs).
  • text2malbolge.py — a linear text→Malbolge compiler (fast; ASCII scope).
  • text2malbolge_bor.py — a branch-on-read compiler with full arbitrary-byte output: every byte value 0–255 is emittable (verified on the reference C), using a data pointer parked 120 cells ahead of the code so the rotate/crazy operands are freely chosen.
  • cat.mb, hello.mb — a Malbolge cat and "Hello World".
  • tests/ — the differential + fuzz + compiler suites.

rtos/ — a Malbolge RTOS for the STM32U585

A from-scratch cooperative real-time kernel where each task is a Malbolge VM. Because the interpreter is a pure state machine, a task's whole context is (a, c, d, mem) and the scheduler advances it by a quantum of cycles with no assembly context-switch. Built for the Arduino UNO Q's STM32U585; the same kernel/VM/display code runs on the host (rendering the LED matrix as ASCII) and on the chip, where it drives the on-board 13×8 charlieplexed LED matrix to scroll "Hello World from Malbolge VM" forever.

cd rtos
make run     # host simulation: scheduler + scrolling matrix as terminal ASCII
make arm     # -> build/arm/firmware.bin for the STM32U585 (3.8 KB flash, ~125 KB SRAM)

The path from idea to hardware

  1. A reference-exact interpreter (so behavior matches real Malbolge).
  2. Compilers, including one that reaches any byte — needed to generate the text the firmware prints.
  3. A kernel that schedules interpreter instances as tasks.
  4. A bare-metal STM32U585 port: default-clock boot, a SysTick-driven charlieplex scan over PF0..PF10, and a 5×7-font scroller fed by a Malbolge task's output. Flashed to a real Arduino UNO Q — and it runs.

Licensing

Original code is Apache-2.0 (see LICENSE). rtos/port/cmsis/ vendors CMSIS device/core headers from ST and Arm, redistributed under their own permissive licenses (headers retained in each file) so the firmware builds self-contained.

About

A Malbolge interpreter, arbitrary-byte compilers, and a cooperative RTOS that runs Malbolge VMs bare-metal on an STM32U585, scrolling text on the Arduino UNO Q LED matrix

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages