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
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.
| Nybble | Does |
|---|---|
0 NOP | Nothing |
1 ACT a | Move nybble a one place along a fixed cycle of all 16 values |
2 INC a 3 DEC a | Add or subtract 1, wrapping |
4 JMP a | Jump to nybble a |
5 NEG a 6 REV a | Flip the bits, or reverse their order |
7 CJM a b 8 CJZ a b | Jump to b if nybble a is not 0, or if it is 0 |
9 LSH a 10 RSH a | Shift left or right |
11 SWP a b | Swap two nybbles |
12 NND a b c | c becomes a NAND b |
13 OUT n | Print byte n as its chart character |
14 OUB | Print all eight bytes |
15 TEM | End |
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.
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.
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
- Self-modifying code: code and data share sixteen nybbles.
- Quine: printing memory prints the program.
- Code as data: every byte is both an instruction and a value.
See also
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-bytesSource
- 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