esolang

INJUQ

One instruction. Add, and jump if the sum equals something else.

ChuckEsoteric08 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 5

The idea

ChuckEsoteric08 made INJUQ, short for increment and jump if equal. Like Subleq it has a single instruction and a memory that holds both the program and its data. The program is written into memory from address 0, four numbers to an instruction, and every other cell holds 0.

The machine

An instruction is four addresses, a b c d.

StepDoes
AddThe number at b is added to the number at a
CompareIf the number at a now equals the number at c, go to d
OtherwiseGo on to the next four numbers

Going to address -1 halts. Two values of b do I/O instead. With -1 a number is read and added to a, and with -2 the number at a is printed. A test that compares a cell with itself is always true, so x -2 x d prints and jumps, and x x x d on an empty cell just jumps.

The specification allows character-based or integer-based I/O. This implementation does integer-based I/O, so each number is printed on its own line, and the character examples print character codes.

Example

The adder reads two numbers into addresses 16 and 17, adds 17 to 16 and prints it.

The adder reads two numbers into addresses 16 and 17, adds 17 to 16 and prints it.

The truth machine compares the number read with the 1 at address 13. On 0 it prints once and halts. On 1 it jumps to an instruction that prints and jumps to itself.

Expected: 0

The "HI" program jumps over its data at addresses 4 and 5 and prints both. In integer I/O they come out as the codes of H and I.

Expected: 72 73

Patterns it teaches

  • One instruction: an add and a conditional jump in one, with I/O folded into two special addresses.

Further

OISC

Write your own in Run Convert a program from INJUQ

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run injuq -e ' 12  -1  13   8
 12  -2  12  -1
 12  -2  13   8
  0   1   0   0' --input '0'
shib manual injuq

Source

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

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

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