esolang

Pit

Meant to make most other esoteric languages look like BASIC. Even a letter goes out one bit at a time.

david.werecat, 2012 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: A

The idea

david.werecat made Pit in 2012 to be extremely low level. Its CPU knows 16 instructions of one byte each, four bits of opcode and four of parameter. It can only work on a cache of 16 bits; memory is bits too, reached through a pointer, and below 0 that pointer reaches into the program itself.

Read the story

There is no print. The CPU sends single bits to a device hub, and the hub reads them as packets. A packet is a start bit 1, three bits naming the device, then a 1 and a data bit for each bit of data, and a 0 at the end. Eight data bits to the console, device 000, write one character. Input comes back the same way, as keypress packets, bit by bit.

The machine

InstructionDoes
NOT n SKP nFlip cache bit n; skip the next instruction when it is 1
GET n PUT nMove a bit between cache bit n and memory at the pointer
INC n DEC n RET 0Move the pointer by n (0 means 16); set it to 0
PSH n POP nPush this instruction's place on stack n; drop one
JMP nJump to the place on top of stack n
JMP 0 FLG 0Jump forward to the matching FLG
SND n RCV nSend cache bit n to the hub; take one bit from it
ERR n HLT n OFF 0Read the error flag; wait 2^n ms; power off

A program is written in this assembly language, one instruction per line, and a line that starts with ~ is a comment. Each input byte waits as a keypress packet with one EOF packet after the last.

Example

The letter A, 01000001, as one packet.

The letter A, 01000001, as one packet. Cache bit 1 is set to 1 and bit 0 stays 0, so SND 1 sends a 1 and SND 0 a 0. Out go the start bit, device 000, eight pairs and the closing 0.

The Hello, world! is 326 instructions of this kind and prints Hello, world!. Its cat is a loop of 69 instructions that waits for a start bit, checks the device is the console, stops at the EOF packet, and copies every keypress packet back out to the console.

Patterns it teaches

  • Tag systems: the specification proves Pit Turing complete by translating Bitwise Cyclic Tag into it.
  • Self-modifying code: the program's own bits sit just below memory 0.

Further

Self-modifying

Write your own in Run Convert a program from Pit

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: pit.

Command line

shib run pit program.txt --input 'abc'

The program is long; save it as program.txt first.

shib manual pit

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/pit.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org