esolang

LIMITED

Four commands, numbers without a bound and a jump to a line number.

DadoDev · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 7 known programs · Test method

Run it

Expected: 0

The idea

DadoDev made LIMITED to have one of the smallest instruction sets possible. There are four commands. Three change a variable and the fourth compares two values and jumps to a line. Every variable is a whole number with no bound, so the specification calls it a variation of the counter machine and Turing complete.

Read the story

Three more commands read and print. The specification leaves them out of the count, as a machine needs no I/O to be Turing complete.

The machine

CommandDoes
SET x ySet x to y
ADD x yAdd y to x
INV xMultiply x by -1
CMP x op y nJump to line n if x op y holds, op one of == != < <= > >=
INP xRead a whole number
OUT xPrint x as a number and a line feed
ASC xPrint the character with code x

Lines are numbered from 1, and an empty line counts. A value is a variable or a number. There is no subtraction, so a program subtracts by adding an inverted copy.

Example

The truth machine.

The truth machine. On 1 it jumps back to line 2 and prints 1 forever; on 0 it prints 0 and falls off the end.

Counting to a number read from the input. Line 5 jumps back to line 3 while the count is at most the maximum.

Expected: 1 2 3 4 5

A triangle of asterisks. ASC 42 prints a star and ASC 10 a line feed.

Expected: * ** ***

The specification also has a Hello, World! of thirteen ASC lines and a multiplication by repeated addition, which both work.

Patterns it teaches

Further

Also in Turing tarpits

Write your own in Run Convert a program from LIMITED

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: limited.

Command line

shib run limited -e 'INP value
OUT value
CMP value == 1 2' --input '0'
shib manual limited

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/limited.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org