Two Fifty Six

From Esolang
Jump to: navigation, search

TFS is a little idea of mine (User:Jercos). I was playing around with logical gates and truth tables, and realized any two-input gate could be represented by reading the Z column of a truth table as a nybble, like so:

1100 A
1010 B
------
0000 False
0001 NOR
0010 B && !A
0011 !A
0100 A && !B
0101 !B
0110 A != B (xor)
0111 !(A && B)
1000 A && B
1001 A == B (xnor, or cmp)
1010 B
1011 B || !A
1100 A
1101 A || !B
1110 OR
1111 True

So for example, for the OR gate, one looks up the A and B combination for the input (A=0 B=1 is column 3) then picks that bit from the code for the gate (column 3 is a "1") and that's the result.

One could easily see how this could be used just as easily for three-input one-output gates, resulting in (ta-da) 256 possible gates. these gates are fairly boring, as they can all be easily represented using two of the sixteen gates above with the ternary operator (I took this shortcut quite bit bit making the table... see below.) however, this *would* allow the gates to perform *any* possible operation, using a shift register (see below, tape.) however, most of the useful gates will simply be repeated over a given space (01100110 for the XOR(B,C) gate, for example, ignores A completely, and thus allows working on the tape without caring what comes back...)

A start on a handmade table of gates, represented in C-like syntax is at http://jercos.dyndns.org/~jercos/256gates.txt (I'm not quite done, only about half-way through as of writing this...)

I figured that this would make a decent basis for a esoteric language that wouldn't be too hard to implement, as I'm not all that great of a coder :P

so, on to TFS itself. TFS, as the name implies, uses 256 different gates, represented by 8 bits. There are three single-byte registers, all of which are passed to any operation, A, B, and C. three more bits address the destination, A (000), B(001), C(010), or the tape (011 for the current cell, 100 moves the tape backwards one bit before writing, 101 moves the tape forward one bit before writing, 110 and 111 do the same for whole bytes).

The tape is a (theoretically) unlimited string of bits, and any operation on the tape saves the old value of the tape in register A after the operation completes (e.g., A for the operation is the old A, A for the *next* operation is the value of the tape before the previous operation. if that doesn't make sense, tmp=*tape;*tape=operation(A,B,C);A=tmp). I added this after I realized there was no way to do bit shifts, and thus, addition, without some kind of shift register. also, tapes of memory and turning completeness seem to be close cousins, so, ya know...