esolang

ReadWrite

Two instructions, READ and WRITE. Printing, input and jumps are all addresses.

Dominicentek, 2021 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hi!

The idea

Dominicentek made ReadWrite in 2021. It has one register, a memory of numbered addresses and two instructions. READ copies an address into the register and WRITE copies the register out. Everything else lives at four negative addresses. Writing to -1 prints a number, writing to -4 prints a character and writing to -3 jumps to that line. Reading -2 skips the next line when it holds 0, and that is the only condition in the language.

The machine

LineDoes
READ aCopy address a into the register
WRITE aCopy the register to address a
WRITE a vWrite the value v to address a
vPut the value v in the register
AddressWrittenRead
-1Print a numberRead a number
-2Keep the valueGive it, and skip the next line if it is 0
-3Jump to that lineThe current line
-4Print a characterRead a character

A value is a number, # for the register, or one calculation such as 0 + 1 or ! 2. Inside a calculation a number is an address, so 0 + 1 adds what is stored at 0 and at 1. Lines count from 1. The specification leaves the size of a number open, and whether a printed number gets a line feed. Numbers are 32-bit integers that wrap, and a number is printed bare.

Example

The truth machine stores the number it reads at -2 and reads it back.

The truth machine stores the number it reads at -2 and reads it back. On 0 that skips the jump to line 6, so line 5 jumps to line 8, which prints 0. On 1 lines 6 and 7 print 1 forever.

Expected: 0

Arithmetic goes through memory. This stores 6 and 7 at the addresses 0 and 1 and multiplies what is there.

Expected: 42

The calculator reads two numbers and then 1 to 5 for add, subtract, multiply, divide and modulo. It keeps a 1 at address 2 and takes it off the choice until a READ of -2 finds 0. All five branches work.

Further

Also in Turing tarpits

Write your own in Run Convert a program from ReadWrite

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run readwrite -e 'READ -1
WRITE -2
READ -2
WRITE -3 6
WRITE -3 8
WRITE -1 1
WRITE -3 6
WRITE -1 0' --input '0'
shib manual readwrite

Source

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

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

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