4 bits, 8 bytes

From Esolang
Jump to navigation Jump to search

4 bits, 8 bytes is an assembly language invented by User:TheBigH for a 4-bit CPU. It is inspired by 2 Bits, 1 Byte.

Commands

Command (Binary) Command (Disassembled) What it does
0000 NOP Do nothing (a NOP)
0001 ACT ACTion. Given value in memory, completely mix it up according to the following:

0000 -> 1100 -> 0110 -> 0010 -> 0111 -> 1000 -> 0001 -> 1011 -> 0100 -> 0011 -> 1110 -> 0101 -> 1001 -> 1010 -> 1101 -> 1111 -> 0000

0010 INC Given value in memory, INCrease given value (wraps)
0011 DEC Given value in memory, DECrease given value (wraps)
0100 JMP Given value in memory, JuMP to that instruction.
0101 NEG NEGate given address by flipping all of it's bits.
0110 REV Given value in memory, REVerse it's bits. For example, 0001 becomes 1000.
0111 CJM Conditional JuMp. Given two addresses, if the value in the first address is nonzero, jump to the second address.
1000 CJZ Conditional Jump but Zero. Like CJM except zero instead of nonzero.
1001 LSH Given value in memory, perform a logical Left SHift on it.
1010 RSH Given value in memory, perform a logical Right SHift on it.
1011 SWP Given two addresses, SWaP the values of them.
1100 NND Given three addresses, NaND the first two addresses together and store the result in the third.
1101 OUT Given a 4 bit number, OUTput the value of that byte as a char*. If the number is more than 7, 8 gets subtracted from it.
1110 OUB OUtputs all Bytes as chars*.
1111 TEM TErMinates the program.
*This uses a modified version of Windows-1252. Here's a chart:
  0123456789abcdef

0 ○■↑↓→←║═╔╗╚╝░▒►◄
1 │─┌┐└┘├┤┴┬♦┼█▄▀▬
2 ▓!"#$%&'()*+,-./
3 0123456789:;<=>?
4 @ABCDEFGHIJKLMNO
5 PQRSTUVWXYZ[\]^_
6 `abcdefghijklmno
7 pqrstuvwxyz{|}~√
8 €‚ƒ„…†‡ˆ‰Š‹ŒŽ♣♥♠
9 ‘’“”•–—˜™š›œž↊↋Ÿ
a π¡¢£¤¥¦§¨©ª«¬∞®¯
b °±²³´µ¶·¸¹º»¼½¾¿
c ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ
d ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
e àáâãäåæçèéêëìíîï
f ðñòóôõö÷øùúûüýþÿ

The instruction pointer can wrap around, thus allowing more "complicated" programs. Since the memory is 8 bytes, you can represent the entire program with just 8 characters. For example:

AAAAAAAA

becomes:

0100000101000001010000010100000101000001010000010100000101000001

which, when disassembled, becomes:

JMP 0x1
JMP 0x1
JMP 0x1
JMP 0x1
JMP 0x1
JMP 0x1
JMP 0x1
JMP 0x1

Programs

Quine

Any program beginning with ï is a quine, for example

ïAmQuine

because when disassembled, ï becomes:

OUB
TEM

also

►aQuine◄

is a self-referential Quine.

Output any 3 characters

ÕÖ×ð○???

where the ??? is replaced with the 3 characters. When disassembled, this becomes:

OUT 0x5
OUT 0x6
OUT 0x7
TEM
NOP
NOP
NOP
?

Output N forever

uÎ♠HNÜŽ´ (a randomly generated program)

Truth Machine

√m√×F○○?

where the ? is replaced with 0 or 1 (number or char). When disassembled, this becomes:

CJM 0xF 0x6
OUT 0x7
TEM
OUT 0x7
JMP 0x6
NOP
NOP
NOP
NOP
?

Infinite loop

○○○○○○○○

Interpreters

https://snap.berkeley.edu/project?username=lionheart921&projectname=4%20bits%2c%208%20bytes by User:TheBigH

See also