PZAB
Every byte is built one bit at a time, through a one-bit register that cannot be set directly.
Zac Herd, 2013 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Zac Herd made PZAB in 2013 to make the programmer work on memory and registers at the level of bits. The machine has 256 cells of 8 bits and five registers. P0 points at a cell and P1 at one of its 8 bits. A and B hold one bit each; they can be set, but only AND, OR and XOR use them. Z holds one bit too; it cannot be set directly, and it takes the result of AND, OR or XOR on A and B.
Read the story
So writing a letter means walking P1 over its bits and writing Z into each one, with ! flipping Z between the ones and the zeros.
The machine
| Command | Does |
|---|---|
+ - | Move P0 to the next or the previous cell |
< > | Raise or lower P1 |
A B | Copy the bit at P0 and P1 into A or B |
a b | Copy Z into A or B |
Z | Write Z into the bit at P0 and P1 |
! | Flip Z |
& | _ | Put A AND, OR or XOR B into Z |
. , | Read a number or a character into the cell |
: ; | Print the cell as a number or as a character |
? ... ~ | Skip to the ~ unless Z is 0 |
2 ... 0 | Run the code up to the 0 that many times, 2 to 9; 1 runs it forever |
Every other character is ignored. Every register starts at 0, as the specification says. The Hello World only works if Z starts at 1, so it prints other bytes. The specification does not say what P1 does past 7. Its Subber only works if P1 stops at 0 and at 7 instead of wrapping around, so it stops there.
Example
This program keeps one cell and turns each letter into the next by writing only the bits that differ.
This program keeps one cell and turns each letter into the next by writing only the bits that differ. Z starts at 0, so the first ! makes it 1 before the first bit is written.
The Adder reads two numbers into cells 0 and 1 and adds them a bit at a time. Cell 2 keeps the carries and cell 3 the sum. The second line does bit 0, and the 7 loop does bits 1 to 7.
The Subber flips the bits of the second number, adds 1 and then adds the first number. Cells hold 8 bits and : prints them from 0 to 255, so 3 minus 10 gives 249.
Patterns it teaches
- Turing tarpit: three bits of logic and a 256 byte memory.
- Encoding tricks: addition and subtraction rebuilt from AND, OR and XOR.
Further
See also
Cell-based
Write your own in Run Convert a program from PZAB
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: pzab.
Command line
shib run pzab -e '.+.-
A+B_++Z-&Z
7--<A+B&+Z_a>B<_+Z&-aB|Z0
+:' --input '3 4'shib manual pzabSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/pzab.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org