Bitwise
An assembly language with no arithmetic, only bitwise operators and jumps.
MD XF, 2018 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Bitwise has 1,000 registers of 32 bits and a short list of instructions, each on its own line. There is no add and no compare; everything is XOR, AND, shifts and NOT. Every instruction that could fail takes a condition, so OUT &72 1 prints H only when register 1 is not 0, and a jump fires only when its second operand is not 0.
The machine
An operand is a register 1, a literal &1, a frame register *1, the register named by register 1 #1, a label @1, or -1 to throw a result away. This implementation follows the C interpreter in the repository aaronryank/bitwise, which is what TIO runs, and leaves out its functions.
| Instruction | Does |
|---|---|
XOR a b c, AND, SL, SR, LSR | Store a op b into c |
NOT a b | Store every bit of a flipped into b |
MOV a b c | Set a to b when c is not 0 |
OUT v c d | Print the byte v when c is not 0 |
IN a c d | Read a byte into a when c is not 0; d gets 1, or 0 at the end |
LABEL n | Remember this line as label n |
JMP t c | When c is not 0, go on after label t, or t lines on; 0 ends |
FRAME DEFRAME | Open a fresh set of frame registers; clear it and go back |
The specification lists OR, but the interpreter has no such instruction and skips it. A label exists only once its line has run, so a jump forward to a label goes to line 0 instead.
Example
The second program XORs each value with 48 to make a digit and shifts right until nothing is left.
The second program XORs each value with 48 to make a digit and shifts right until nothing is left. The third is the specification's frame example.
Patterns it teaches
operations in place of counting.
- Counter machines: registers and conditional jumps, with bit
operations in place of counting.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Bitwise
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: bitwise.
Command line
shib run bitwise -e 'MOV 1 &1 &1
IN 2 1 3
OUT 2 3
JMP &-3 3' --input 'cat'shib manual bitwiseSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/bitwise.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org