Subskin
One instruction, subtract and skip if negative, and a whole interpreter in 148 bytes of Ruby.
Jannis Harder, 2005 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Jannis Harder made Subskin in 2005. The name is short for "subtract and skip if negative". Like Subleq it has a single instruction, so the program is nothing but numbers in memory, and code and data share the same cells. A program changes its own instructions to make loops and to walk through a list.
Read the story
Its reference interpreter is 148 bytes of Ruby, released into the public domain.
The machine
Memory is a row of unbounded integers, one per line of the program, written in hex. Three cells near the start are registers.
| Cell | Role |
|---|---|
| 0 | The instruction pointer |
| 1 | Output. When it is 0 or more it is printed as a byte and set back to -1. A value of 256 or more ends the program |
| 2 | Input. When it is below 0 a byte is read into it, or 256 at the end of the input |
Each step first does the output and input, then reads the three cells A, B and R at the instruction pointer and sets memory[R] = memory[A] - memory[B]. If the result is negative the pointer moves on 6 cells, so it skips the next instruction; otherwise it moves on 3.
There is no halt instruction. A program stops by reading a cell that does not exist, or by printing 256, because the interpreter turns every error into a quiet end.
Example
Cell 1 starts as 48, the H, so it is printed before anything runs.
Cell 1 starts as 48, the H, so it is printed before anything runs. The instruction at cell 3 copies the cell its first word points to into the output, minus cell 2, which is 0. The instruction at cell 6 adds one to that pointer, since cell 1 is -1 again by then. The one at cell 9 sets the instruction pointer to 0, and the next step adds 3, which loops back. When the copied cell is 100, which is 256, the program ends.
A cat program. The instruction at cell 3 sets cell 2 to -1, which asks for a byte. The one at cell 9 copies that byte into the output, and the one at cell 12 sets the pointer to -3, so the next step lands on cell 3 again. At the end of the input the byte is 256, and printing it ends the program.
Patterns it teaches
- One instruction: one subtraction with a conditional skip is enough for any computation.
- Self-modifying code: the only way to walk through a list is to change the address inside an instruction.
Try this
- Change the hello world to print your name.
- Print each input byte twice.
- Hard: print the input backwards.
Further
See also
OISC
Self-modifying
Write your own in Run Convert a program from Subskin
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: subskin.
Command line
shib run subskin -e '3
-1
0
6
7
2
0
1
0
2
6
1
D
3
0' --input 'meow'shib manual subskinSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/subskin.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org