Modulous
Assembly in square brackets. A jump counts modules, not lines.
Abyxlrz · Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Abyxlrz made Modulous, a stack language that looks like assembly. Every command is a module in square brackets, such as [PSH INT 66] or [JMP B 2], and a jump moves the module pointer a number of modules forward or back. A jump can test the top of the stack, and the test leaves it there.
Read the story
A string is pushed back to front, so its first character ends on top, and printing pops it in order. There are also four variables, but no module puts a variable back on the stack. They can only be set, changed and printed.
The machine
| Module | Does |
|---|---|
[PSH INT 5] [PSH STR "hi"] | Push a number, or the characters of a string |
[POP] [DUP] [SWP] | Pop, duplicate, swap |
[ADD 5] [SUB 5] | Change the top number |
[PRT INT] [PRT STR] | Pop the top and print it as a number or a character |
[INP INT] [INP STR] | Read a number, or push a line of input |
[JMP F 3] [JMP B 1 NIF 0] | Jump 3 modules on, or 1 back when the top is not 0 |
[JMP F 3 IF 0] | Jump 3 modules on when the top is 0 |
[RST] [END] | Go back to the first module; stop |
[PSH VAR1] [VAR1+10] [PRT VAR1 INT] | Copy the top into a variable, add to it, print it |
[RND 100] | Push a random number from 0 to 100 |
Example
The Hello World pushes 13 characters with H on top, then prints and pops until the top is 0.
The Hello World pushes 13 characters with H on top, then prints and pops until the top is 0. The stack is empty by then. The specification does not say what a test sees on an empty stack; this implementation makes it 0, so the loop ends after the !.
In the truth machine a 0 jumps three modules on, to [PRT INT] and [END]. A 1 jumps four on, to a loop that duplicates and prints the 1 forever. Any other number reaches [RST], and the program reads again.
Patterns it teaches
- Stack machines: one stack, tested in place by the jumps.
Further
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Modulous
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: modulous.
Command line
shib run modulous -e '[PSH STR “Hello, World!”][PRT STR][JMP B 1 NIF 0]'shib manual modulousSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/modulous.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org