Backwords
Machine code written by hand in ASCII, on a program that loops forever.
1hals, 2020 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
1hals made Backwords in 2020. It was planned as a stack-based golfing language, and the specification says it came out closer to writing machine code by hand. Every value is a byte from 0 to 255 that wraps around. Numbers are written in hexadecimal after a #, so #FF is 255. The program runs in an endless loop; it stops on ;, or when a command finds too few numbers on the stack.
Read the story
A string goes on the stack in the order it is written, so its last character ends on top and prints first. To print a text you write it backwards.
The machine
| Command | Does |
|---|---|
# 0-F | Push 0; make the top 16 times itself plus the digit |
'c "text" | Push one character; push a text, its last character on top |
: _ s u $ | Duplicate, drop, swap, empty the stack, push its size |
+ - * / % | Arithmetic, with the top as the left operand |
` & ` | ` | Bitwise not, and, or |
= > < | Push 255 or 0 for equal, less than, greater than |
, ? | Print a byte; read a byte |
n z | Pop; skip the next character unless the value was not 0, or was 0 |
^ v \ | Jump forward or back by the popped value; jump to the start |
. | Pop a value and run it as a command |
{ } @ ! | Previous or next page of 256 bytes; load; store |
i I | Push the character n places before or after |
; | Halt |
Every other character is a comment. In this implementation the end of the input also ends the program, so the cat stops after its input.
Example
The Hello World pushes 0, a line feed and the reversed text.
The Hello World pushes 0, a line feed and the reversed text. Then it loops on :z;,, which prints until it duplicates the 0 at the bottom and halts. #6v jumps 6 characters back to the :.
The star printer counts down from '*, which is 42, and prints a star each time. At 0 the n^ jumps 13 characters forward to # A,;, which prints a line feed and halts.
?. runs its input as a program, one character at a time.
The longer Hello World ends on A,; without the # that starts a number. The A finds an empty stack, which ends the program before the line feed.
Patterns it teaches
- Stack machines: every command works on one stack of bytes.
- Code as data:
iandIread the program's own characters, and.runs a value as a command.
Further
See also
Stack-based
Write your own in Run Convert a program from Backwords
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: backwords.
Command line
shib run backwords -e '?,' --input 'cat'shib manual backwordsSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/backwords.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org