BitBitJump
One instruction that does not even compute: copy one bit, then jump. Every if is made by copying a bit into a jump address.
Oleg Mazonka, 2009 · Turing complete: with unbounded memory · ●●● hard · esolangs.org
Tested with 2 known programs · Hello World on Try It Online: does not finish · Test method
Run it
The idea
Subleq gets by with one instruction, but that instruction still subtracts. Oleg Mazonka asked whether a machine needs arithmetic at all. BitBitJump's answer is no. Its one instruction copies a single bit from one address to another, and jumps.
Read the story
There is no if and no compare. The trick is that the jump address is itself data in memory. Copy a bit into one of the jump address's bits, and the jump goes to one of two places depending on that bit. That is a branch. Build enough branches and you have lookup tables, and with lookup tables you have addition, comparison, everything.
Mazonka wrote an assembler with a macro library on top, so people program it a level up, much as P′′'s author did.
The machine
Memory is a long array of bits, grouped into words of W bits (16 in this implementation). Addresses count bits, not words. The instruction pointer is a bit address too.
A B C: copy the bit at address A to the bit at address B, then jump to address C
A, B and C are the three words starting at the pointer. The all-ones address (-1) is special in the usual convention, followed by this implementation: copying from it reads an input bit, copying to it writes an output bit (lowest bit of each byte first), and jumping to it halts.
Example
Print H (72, binary 01001000).
Print H (72, binary 01001000). Store 72 as data in word 24, which starts at bit 24 × 16 = 384. Eight instructions each copy one of its bits to the output, and the last one halts.
384 -1 48 copy bit 384 (lowest bit of 72) to output, jump to the next instruction at bit 48
385 -1 96 ...
...
391 -1 -1 the eighth bit, then halt
72 word 24: the data
That is only copying. The branch trick is the interesting part. This program prints 1 if a data bit D is 0, and 0 if it is 1: a NOT gate.
176 86 48 ; copy bit D (word 11) into bit 6 of word 5, the C of the next instruction
96 96 128 ; copy Z to Z (does nothing), jump to 128, or to 128 + 64 if D was 1
0 1 ; words 6 and 7: Z = 0 and O = 1
112 -1 240 ; bit 128: write a 1 bit, go on to 240
0 ; word 11: the data bit D
96 -1 240 ; bit 192: write a 0 bit, go on to 240
96 -1 288 96 -1 336 96 -1 384 112 -1 432 112 -1 480 96 -1 528 96 -1 -1
; bit 240: the other seven bits of '0' or '1' (0 0 0 1 1 0 0), then halt
Save it as not.bbj and run shib run bitbitjump not.bbj. It prints 1. Change the 0 in word 11 to 1 and it prints 0.
Patterns it teaches
- One instruction: the most extreme kind. Not even arithmetic, data movement and a jump.
- Self-modifying code: every decision is made by a program rewriting its own jump target. There is no other way to branch.
- Code as data: instructions, addresses and data are all just bits in one array.
Try this
- Print
Hiby extending theHprogram. - Make the NOT program read D from input (copy from -1 instead of from word 11).
- Hard: an AND gate. Copy two data bits into two different bits of one jump address, and lay out four landing places.
Further
- esolangs.org/wiki/BitBitJump
- Oleg Mazonka's BitBitJump page, with the assembler, the macro library and an emulator.
- Its arithmetic cousin: Subleq.
See also
OISC
Self-modifying
Write your own in Run Convert a program from BitBitJump
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: bitbitjump.
Command line
shib run bitbitjump -e '384 -1 48 385 -1 96 386 -1 144 387 -1 192 388 -1 240 389 -1 288 390 -1 336 391 -1 -1 72'shib manual bitbitjumpSource
- Module
langs/museum/ports.js- Interpreter
langs/museum/bitbitjump.js,langs/common.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org