We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

TetraBit

From Esolang
Jump to navigation Jump to search

TetraBit is an esoteric assembly language I designed which uses a slightly 4 Bits, 8 Bytes aesthetic, however with different instructions and unlimited program size. You can write it in either assembly- or machine-code style. There are 16 memory addresses, 0-15 (or F) and they are split up like this:

  • Addresses 0-6 are the 7 free variables.
  • Addresses 7-E make up a 4x2 screen.
  • Address F is a read-only which holds one random value, 0-F, changing every instruction.
Opcodes
Instruction 6502-esque description
0 NOP instruction. Mainly there to fill lines, however it also updates the screen.
1 X LDA. Loads the value at address X.
2 X Y STA. Stores the value X in address Y.
3 X Y INC. Increments the value at address X by Y.
4 X Y DEC. Decrements the value at address X by Y.
5 X Y MOD. Turns the value at address X into itself modulo Y.
6 X Y MOV. Moves the value in address X to address Y and clears the value at address X.
7 X Y AND. Logical-ANDs the value at address X with value Y.
8 X Y ORA. Logical-ORs the value at address X with value Y.
9 X Y XOR. Logical-XORs the value at address X with value Y.
10 (or A) X NOT. Bitwise NOTs the value at address X.
B X Y BEQ. Branches if the value at address X and value Y are equal.
C X "DSR". Defines a subroutine with label value X.
D "ENS". Ends the current subroutine being defined or used (subroutines are implicit when inside BEQs).
E X "CSR". Calls the subroutine with label value X.
F HLT/END. Halts the program.

An example of using BEQ correctly (linebreaks added for readability):

B 5 0
3 5 1 ; if true
D     ; end true subroutine
3 5 2 ; if false
D     ; end false subroutine
D     ; merge branches by ending branch subroutine
F     ; end program (must go at end of full program)

Here it is without linebreaks, as machine code in TetraBit:

B 5 0 3 5 1 D 3 5 2 D D F

The memory is visualized like this:

0 1 2 3 4 5 6
      / \
789A | F |
BCDE  \ /

Now how must 0-F look as colors on the screen? Like this.

Colors
Value RGB color (3-bit when possible)
0 #000
1 #808080
2 #00f
3 #8080ff
4 #0f0
5 #80ff80
6 #0ff
7 #80ffff
8 #f00
9 #ff8080
A #f0f
B #ff80ff
C #ff0
D #ffff80
E #fff

F is transparent, so on some interfaces it will be white, on others black, depending on how it is handled. It may also be a light-gray/white checkerboard, a common pattern to show transparency.

Example programs

Multiplies two values together:

C 0 1 3 3 3 1 4 2 1 D 1 0 2 2 1 1 2 3 1 2 E 0 F

Or, more readably:

C 0   ; define subroutine 0 as:
1 3   ; load address 3
3 3 1 ; increment address 3 by 1
4 2 1 ; decrement address 2 by 1
D     ; end subroutine           ;; (definition's end)
1 0   ; load address 0
2 2 1 ; store 2 at address 1
1 2   ; load address 2
3 1 2 ; increment address 1 by 2
E 0   ; call subroutine 0
F     ; end

Paints a hard-coded checkerboard of blue and cyan pixels:

2 2 7 2 2 9 2 2 C 2 2 E 2 6 8 2 6 A 2 6 B 2 6 D F

Or:

2 2 7
2 2 9
2 2 C
2 2 E
2 6 8
2 6 A
2 6 B
2 6 D
F

Its variant: 4BI English

TetraBit has a variant named 4BI English which is like this:

0 = DO NOTHING

1 X = LOAD ADDRESS X

2 X Y = STORE X IN Y

3 X Y = ADD X TO Y

4 X Y = SUBTRACT Y FROM X

5 X Y = TAKE X MOD Y

6 X Y = MOVE X TO Y

7 X Y = TAKE X ANDED WITH Y

8 X Y = TAKE X ORED WITH Y

9 X Y = TAKE X EXCLUSIVELY ORED WITH Y

A X = INVERT X

B X Y = IF X IS EQUAL TO THE VALUE Y:

( note: this one needs indentation and an ELSE statement )

C X = DEFINE SUBROUTINE X:

( same note here)

D is no longer used in 4BI English.

E X = CALL SUBROUTINE X

F = END