The general purpose calculator (GPC) is a a way to design universal computation inside conway's game of life. the first calculator was written by Adam P.Gaucher in 2011, it was printing the number of pi, and it had all the basic general purpose components. The programs are written in a special assembly code called APGsembly (and a compiler was written by Dave Greene) to create a state in CGOL that will correspond to the code.
The GPC is basically finite-state machines, where each line in a program corresponds to a state, and you have JUMP instructions for every return value. Each line can trigger one or more actions and you have to make sure that you execute exactly one reaction that returns a zero/nonzero value.
The calculator has a ticking clock in form of glider gun (of period 2^22 and higher), which emits a glider each time an operation was executed with return value either Z/NZ (represented by two possible different emitted glider lanes), as result of the last command. The commands are triggered by an input glider into special computational units on specific lanes to trigger a specific action (like ADD, SUB, WRITE, READ, INC etc.), defined by the APGsembly code.
Thus the GPC has four major physical components:
- Programming code.
- Computational unit array.
- Printer and SQ
Clock: the computational cycle
Each 2^22 generations, a glider gun is initiating an action based on output from previous cycle (it waits until output has returned).
- The new action could be either Z or NZ.
- Each cycle is expected to return exactly one output, either Z or NZ.
The code consist of operations logic per code name. Each code can react differently to Z or NZ. The program consists of lines of code, each code corresponds to two lines of code (one for Z and one for NZ). The program must start with INITIAL, and will halt (if nothing is returned) or run forever if the program was written by the rules (i.e. single return per line).
Each line of code consists of 4 parts:
CodeName; Z/NZ; NextCodeName; OP1, OP2, OP3 etc.
- CodeName. Each line has a code name.
- Z/NZ. Each line has a policy of operations depending on returning Z or NZ from the previous cycle.
- NextCodeName. Each line + Z/NZ defines the next execution line.
- Op. Each line + Z/NZ defines a list of operations to be executed. The operations are inputs to the computational units. Some operations will not return anything and only change the state of the unit and some will return either Z or NZ depending on the internal state and the logic of some particular unit. It's programmer task to make sure there is exactly one return value.
NOP - The NOP operation is sending Z output directly.
INITIAL; Z; A2; NOP
A1; Z; A2; INC T0
A1; NZ; A2; INC T0
A2; Z; A1; READ T0, SET T0
A2; NZ; A1; READ T0, SET T0
We have 6 types of units, each type has several instruction commands.
- R - Sliding block register.
- T - Binary string register.
- ADD - adder.
- SUB - subtractor.
- MUL - we're not sure how to use.
- SQ - a two dimensional (square) array of data.
The calculator can have arbitrary number of R and T units and a single ADD, SUB, MUL units.
R: Sliding block
- Sliding block in the code is always starting from R. For example R0, R1, R2 etc.
- Sliding block has very simple logic. They represent a single number, and all you can do with them is INC (increase by 1) and TDEC (decrease by 1).
- INC Rx will just increase the register by 1. Will not return anything.
- TDEC Rx will decrease the register by 1. Will return NZ if the register > 0 and Z otherwise.
T : Binary string register
- The binary string registers are starting with T. For example T0, T1, ..T14 in APGsembly.
- They have a "reading head". It can be moved with INC and DEC just like sliding block.
- They can store arbitrarily-large binary strings. A program can only retrieve one bit at a time using READ command, followed by SET, RESET that can be called "WRITE 1" and "WRITE 0".
- INC Tx increase the position of reading head. Returns Z unless the space is empty then it returns NZ.
- DEC Tx decrease the position of reading head. Returns NZ unless at 0.
- READ Tx return the state of the binary string value located at reading head. Returns Z if the value is 0 and NZ if 1.
- SET Tx sets the state of the binary string to 1. Must be after READ operation which deletes the state.
- RESET Tx setse state of the binary string to 0. Must be after READ operation which deletes the state.
One should think about the adder as having two bits A and B. Each of them has 0 or 1 option, and each of the options is an input to the adder. A input is just changing the state of the Adder unit, and B input returns the result.
- A0 is ignored case because there is nothing to change.
- A1 is a valid input
- B0, B1 should come after A was initialized.
- The adder returns (Ax + By + Memory) % 2
- The adder stores Memory = (Ax + By + Prev Memory >= 2)
- The memory bit is always stored in the unit when existent.
- If you not sure about the state of the adder just send B0 and you can be sure the Memory is cleaned.
The operation code would look like ADD A1 or ADD B0.
The subtractor works exactly as adder, just for subtracting two numbers bit by bit keeping in memory 0 or 1.
MUL keeps inside a register a number between 0 and 10. While MUL 0 is dividing the number by 2, and MUL 1 is dividing it by 2 and adding 5. As mentioned we're not sure how it used.
SQ: a two dimensional array
- The SQ register is starting with SQ. For example INC SQ, DEC SQ, READ SQ etc. in APGsembly.
- The SQ has two arms X and Y. Each arm can be moved with INC and DEC. For example INC SQX, DEC SQY.
- A program can retrieve a bit located in (X, Y) by READ command. Unlike T where you must follow with SET, RESET the SQ will erase the (X, Y) bit only if it was existing. It also has only SET SQ command.
- INC SQX/SQY increase the position of X/Y arm. Will not return anything.
- DEC SQX/SQY decrease the position of X/Y arm. Returns NZ unless at 0.
- READ SQ return the state of the binary value located at (X, Y). Returns Z if there is nothing and NZ otherwise.
- SET SQ sets the state of the binary string to 1. Must be after READ operation which deletes the state.
The printer can print "." and digits 0-9. It will not return anything.
The command is OUTPUT x
You can see the discussions and examples as well you can ask question in this conwaylife.com forum thread.