esolang

Protogen

A program is a file of bytes cut into lines of equal width. The first byte of each line says what to do.

Joseppi1, 2022 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hi

The idea

Joseppi1 made Protogen in 2022, and the specification suggests a hex editor to write it. The first byte of the file sets the width of a line, as a power of two, so 02 makes every line 4 bytes. After that each line is one instruction byte and its parameters. Four byte registers do the work. A and B are inputs, C takes results and E takes carries and other special news.

Read the story

There is no memory besides the program itself. To keep a number you store it into a byte of the code and load it back, and a store into an instruction changes what the program does.

The machine

ByteCharDoes
41 42A BPut the first parameter into A or B
61 62a bLoad A or B from the code byte at the address
63 65c eStore C or E into the code byte at the address
2B 2D+ -C is A plus or minus B; E is the carry or borrow
26 7C 5E& | ^C is A and, or, xor B
6AjJump to the address
3E 3D 3C> = <Jump when A is greater than, equal to or less than B
72rJump, and come back to the next line at a 00 line
00End of a block, or of the program
2C 3B, ;Read a character or a number into C
2E 3A. :Print A as a character or a number
3F?C is a random number from A to B

An address is the parameter bytes read little-endian. Any other first byte makes the line a comment. A program is written as the specification writes it, two hex digits a byte, spaces and line breaks ignored.

Example

A line of 41 48 puts the code of H into A, and 2E prints A.

A line of 41 48 puts the code of H into A, and 2E prints A.

A countdown. A starts at the digit 5 and is printed at address 8. Then 1 is taken off, the result goes into byte 1 of the first line, which never runs, and comes back into A. The jump to 8 repeats while A is above the digit 0.

Expected: 54321

The truth machine prints a prompt, reads a character and stores it in the last byte of its own read line. On 0 it jumps to a print and stops; on 1 it loops forever.

Expected: > 0

The specification also has 99 bottles of pop on the wall, which calls two subroutines with r and keeps its count in the fourth byte of a line.

Patterns it teaches

Further

Also in Turing tarpits

Write your own in Run Convert a program from Protogen

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run protogen -e '02 00 00 00 41 3E 00 00 2E 00 00 00 41 20 00 00 2E 00 00 00 2C 00 00 00 63 17 00 00 61 17 00 00 42 30 00 00 3D 30 00 00 2E 00 00 00 6A 28 00 00 2E 00 00 00 00 00 00 00' --input '0'
shib manual protogen

Source

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

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

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