2 Bits, 1 Byte
A whole computer in one byte. The program is its memory, its memory is four instructions, and the output is the memory.
Gilbert189, 2021 · Turing complete: no · ●○○ easy · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Gilbert189 wrote an assembly language for a 2-bit CPU with one byte of memory. Every program is a single character, and there are only 256 of them. The specification lists all 256 with what each one prints, and this implementation gives the same answer for every one of them.
Read the story
Since the program and the data are the same byte, the only way to compute is to rewrite your own instructions. ACT changes another instruction, and END prints the byte as it is at that moment.
The machine
The byte is split into four 2-bit slots, the most significant first. The pointer starts on slot 0 and wraps round after slot 3.
| Bits | Name | Does |
|---|---|---|
00 | DON | Nothing |
01 | ACT | Change the slot named by the next slot, 00 to 11, 01 to 10, 10 to 00, 11 to 01 |
10 | JMP | Jump to the slot named by the next slot |
11 | END | Print the whole byte and stop |
Example
a is 01 10 00 01.
a is 01 10 00 01. ACT 10 turns slot 2 from DON into END, and the pointer lands right on it. The memory is now 01 10 11 01, which is m.
Every digit is a quine. A digit starts with 0011, so the program does nothing and then prints itself. Of the 256 programs, 84 never stop; ' is DON JMP 01, which jumps to itself forever.
Further
Ideas it shows
See also
Binary
Self-modifying
Write your own in Run Convert a program from 2 Bits, 1 Byte
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 2-bits-1-byte.
Command line
shib run 2-bits-1-byte -e 'a'shib manual 2-bits-1-byteSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/2-bits-1-byte.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org