esolang

4 bits, 8 bytes

A whole computer in eight characters, where the program is the memory and the memory is the program.

TheBigH, 2023 · Turing complete: no · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: ïAmQuine

The idea

TheBigH made 4 bits, 8 bytes in 2023 for an imagined 4-bit CPU, after 2 Bits, 1 Byte. Memory is eight bytes, so a program is exactly eight characters. Each character is one byte from a modified Windows-1252 chart, and each byte is two 4-bit instructions or arguments.

Read the story

There is nothing else to store data in, so every instruction that changes memory changes the program. Any program starting with ï is a quine. ï is byte EF, which is the instruction that prints all of memory followed by the one that ends.

The machine

Sixteen nybbles, addressed 0 to 15. The pointer starts at 0 and wraps round. Arguments are addresses.

NybbleDoes
0 NOPNothing
1 ACT aMove nybble a one place along a fixed cycle of all 16 values
2 INC a 3 DEC aAdd or subtract 1, wrapping
4 JMP aJump to nybble a
5 NEG a 6 REV aFlip the bits, or reverse their order
7 CJM a b 8 CJZ a bJump to b if nybble a is not 0, or if it is 0
9 LSH a 10 RSH aShift left or right
11 SWP a bSwap two nybbles
12 NND a b cc becomes a NAND b
13 OUT nPrint byte n as its chart character
14 OUBPrint all eight bytes
15 TEMEnd

Example

The quine, and the program that prints its last three characters.

The quine, and the program that prints its last three characters. Õ is D5, OUT 5, and so on; ð is F0, the end.

Expected: abc

The truth machine with 0 in its last place. √m is CJM F 6. The low nybble of 0 is 0, so it does not jump, prints byte 7 and ends. With 1 it jumps into a loop that prints 1 for ever.

Expected: 0

The specification's hiyaworl prints a changed copy of itself for ever, and changes it more on every pass, as in aiyaîorlaiyaîorlhiyaîorc and on.

Patterns it teaches

Further

Binary

Self-modifying

Write your own in Run Convert a program from 4 bits, 8 bytes

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: 4-bits-8-bytes.

Command line

shib run 4-bits-8-bytes -e 'ïAmQuine'
shib manual 4-bits-8-bytes

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/4-bits-8-bytes.js

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

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