3 Bits, 3 Bytes

From Esolang
Jump to navigation Jump to search

3 Bits, 3 Bytes is an assembly language invented by User:None1 for a 3-bit CPU. It is inspired by 2 Bits, 1 Byte.

Commands

Command (Binary) Command (Disassembled) What it does
000 NOP Do nothing (a NOP)
001 TEM TErMinate the program
010 OUT Given a 3-bit value x after it, OUTput the x-th byte. (If x>=3, it does nothing)
011 INP Given a 3-bit value x after it, INPut the x-th byte. (If x>=3, it does nothing)
100 INC Given value in memory, INCrease given value (wraps)
101 JMP JuMP. Jump (unconditionally) to address specified.
110 CJM Conditional JuMp. Given two addresses, if the value in the first address is nonzero, jump to the second address
111 NEG NEGate given address, formally, if its value is x, let it be 7-x

The instruction pointer can wrap around, thus allowing more "complicated" programs.

Programs

Since the memory is 3 bytes, you can represent the entire program with just 3 characters. For example:

AB@

becomes:

010000010100001001000000

which, when disassembled, becomes:

OUT 000b
OUT 100b
TEM
TEM
NOP
NOP

Which outputs A.

Examples

Quine

A�ˆ

In hex dump:

41 14 88

Disassembled:

OUT 000b
OUT 001b
OUT 010b
TEM
NOP

Partial Truth Machine

010 010 110 111 000 001 000 00n

Where n is replaced with the input (1 or 0), the zero input program Kp@ prints @ once, while the one input program KpA prints A infinitely. Disassembled:

OUT 010b
CJM 111b 000b
TEM
NOP
NOP (zero input)/TEM (one input)

Output any character

Hÿ?

Where ? is replaced with the character you want to output.

Disassembled:

OUT 010b
TEM
...

The ... part is ommited because it largely depends on the character you want to print and will not be executed because of the TEM command.

See also

External resources