Stack machine

For discussion of other cellular automata.
Post Reply
User avatar
wirehead
Posts: 276
Joined: June 18th, 2022, 2:37 pm
Location: /dev/full
Contact:

Stack machine

Post by wirehead » December 19th, 2022, 10:35 pm

I had an idea for a stack machine computer that could be implemented in cellular automata.

It would have 8 basic instructions:
  1. Push a constant
  2. Drop the top value
  3. Store a value on the heap
  4. Read the heap
  5. Call a subroutine
  6. Return from a subroutine
  7. Jump backwards and forwards based on the top stack value
  8. Perform an operation on the top two stack items, push the result
The machine would be in the center and the data would be laid out around it in the 4 quadrants of the plane. Temporary value would be squeezed on the extra space left in the axes.

Quadrant I would hold the program data. Each subroutine would be a row of commands.

Quadrant II would hold the stack. They would be expressed as binary bits, extending upward, with the LSB on the right.

Quadrant III would hold the heap. It would be laid out with one value per row.

Quadrant IV would hold the "Return stack" so when it executes a return instruction it knows how and where to jump back to.

I thought I would implement it in WWEJ3 (hence this being in the OCA board). Here is my first attempt at a read/write arm.

Code: Select all

x = 40, y = 148, rule = WWEJ3
4.36C$4.C34.C$4.C32.C.C$37.C.C$36C.C.C$C34.C.C.C$C32.C.C.C.C$30.D2.C.
C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.F.C.F$33.C.B.C.B$33.G.C.G
.C$33.B.F.B.F$33.C.B.C.B$33.C.C.C.C$33.E.E.E.E$33.B.B.B.B$33.C.C.C.C$
33.C.K.C.K$33.C.B.C.B$33.C.C.C.C$33.C.E.C.E$33.C.B.C.B$33.C.C.C.C$33.
C.E.C.E$33.C.B.C.B$33.C.C.C.C$33.C.K.C.K$33.C.B.C.B$33.C.C.C.C$33.C.C
.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.
C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$
33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.
C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C
.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.
C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$
33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.
C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C
.C.C$33.C.C.C.C$33.C.C.C.C$33.C.F.C.F$33.C.B.C.B$33.C.C.C.C$33.C.F.C.
F$33.C.B.C.B$33.C.C.C.C$33.C.E.C.E$33.C.B.C.B$33.C.C.C.C$33.C.K.C.K$
33.C.B.C.B$33.C.C.C.C$33.C.A.C.A$33.C.B.C.B$33.C.C.C.C$33.C.C.C.C$33.
C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C
.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.
C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$
33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.C.C.C.C$33.
C.F.C.F$33.C.B.C.B$33.G.C.G.C$33.B.F.B.F$33.C.B.C.B$33.C.C.C.C$33.F.F
.F.F$33.B.B.B.B$33.C.C.C.C$33.C.K.C.K$33.C.B.C.B$33.C.C.C.C$33.C.E.C.
E$33.C.B.C.B$33.C.C.C.C$33.C.E.C.E$33.C.B.C.B$33.C.C.C.C$33.C.K.C.K$
33.C.B.C.B$33.C.C.C.C$33.C.C.C.C!
The commands are: reset to 0 and move up, move left and read (I replaced the read instructions with null electrons so they wouldn't clash with the next instruction), and reset to 0 and move down.

It uses four wires so that it doesn't have to count how far to the left it has moved, and can just wipe the arm out and reset to 0 quickly. The 2nd arm is so it will always produce a return signal and can tell a wire (state 3) or an isolator (state 4) from empty space (state 0).

When I have more ideas I will put them here and anyone else is welcome to contribute as well.
Langton's ant: Can't play the drums, can be taught.

User avatar
wirehead
Posts: 276
Joined: June 18th, 2022, 2:37 pm
Location: /dev/full
Contact:

Re: Stack machine

Post by wirehead » December 22nd, 2022, 8:04 pm

Here is what I have so far for an arm controller:

Code: Select all

x = 90, y = 165, rule = WWEJ3
44.5C$44.C3.C$44.C.C.C$46.C.C$40.5C.C.C$40.C3.C.C.C$40.C.C.C.C.C$42.C
.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.
C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C
$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$
42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.
C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C
.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.
C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$
42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.
C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C
.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.
C$42.C.C.C.C$42.C.C.C.C$42.C.C.C.C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.C$6.C3.C11.C3.C
5.C13.C3.C3.C11.C3.C5.C9.C$7.8C8.8C.C13.C4.8C8.8C.C9.4C$6.C3.C.D.C7.C
3.C.D.C.C13.C3.C3.C.D.C7.C3.C.D.C.C$6.CD2.D2.C8.CD2.D2.C2.C13.C3.CD2.
D2.C8.CD2.D2.C2.C$6.C4.2C9.C4.2C3.C13.C3.C4.2C9.C4.2C3.C$6.C.D.C.D9.C
.D.C.D3.C13.C.D.C.D.C.D2.4C.D.C.D.C.D3.C.12C$7.3C13.3C6.C13.C.C2.3C5.
C2.C.C2.3C6.C.C$6.C.D13.C.D7.C12.6C.D6.C.6C.D5.D5CD$6.C15.C9.C12.C2.C
10.C.C2.C11.C.C$6.C15.C9.C12.15C.16C.3C$6.C15.C9.C13.C.C13.C.C11.3C.C
$6.C15.C9.C13.C.D.4C8.C.D.8C6.C$6.C15.C9.C13.C.C.C2.C8.C.C.C6.C6.C$6.
C15.C9.C13.6C.C8.6C5.8C$6.C15.C9.C15.C2.C.C10.C2.C12.C$6.C15.C9.20C.
15C12.C$6.C15.C25.C.C13.C.C13.C$6.C15.C25.D.C.6C6.D.C13.C$6.C15.C27.C
.C4.C8.C13.C$6.C15.C25.D5CD2.10C13.C$6.C15.C27.C.C27.C$6.13C.31C.3C
25.C$18.C.C29.3C.C25.C$16.D5CD31.C25.C$18.C.C33.C25.C$16.3C.35C25.C$
16.C.3C33.C25.C$16.C37.C25.C$16.C37.C25.C$16.C37.C25.C$16.C37.C25.C$
16.C37.C25.C$16.C37.C25.C$16.C37.C25.C$16.C37.C25.C$16.C37.C25.C$16.C
37.C25.C!
The three inputs on the bottom are (from left to right) down, up, and read. The outputs go out the right side.
Langton's ant: Can't play the drums, can be taught.

Post Reply