## Programmable computer

For discussion of specific patterns or specific families of patterns, both newly-discovered and well-known.
Coban
Posts: 12
Joined: June 26th, 2016, 3:50 pm
Location: France

### Programmable computer

Hey,
I made an in-game 8bit programmable computer
the computer, logic gates and programming instructions are here:

a video of the computer computing Fibonacci seqence:

it is only composed of
-Buckaroo reflectors
-Period-60 glider guns
-Glider duplicators

blah
Posts: 244
Joined: April 9th, 2016, 7:22 pm

### Re: Programmable computer

Impressive! I believe this is the first 8-bit computer in a cellular automaton (And first computer of any specific word size in life).

It's definitely my favourite now. Just to get this right, the memory spaces are as follows (correct me if I'm wrong):
32 items of ROM ("Program").
8 bytes of RAM (registers labeled a-h) ("Memory")
1 byte display ("Printer")

It looks like the items in ROM are 18 bits. What are those bits used for?

RAM address 000 ("h") is used as the program counter (PC). I would assume only the least significant 5 bits are used.
Jumpif makes sense, but why is there a GOTO instruction? Wouldn't it make more sense to use "write h (destination)"?

I'll probably write some programs for it myself if I can get python to work. Also, are there any other programs you've written, other than the fibonacci one?
succ

Coban
Posts: 12
Joined: June 26th, 2016, 3:50 pm
Location: France

### Re: Programmable computer

Yes, you're right about memory spaces

The items in the ROM are 21bits:
4 bits for the instruction
3 bits for the write address
8 bits for data to write to the RAM

Yes, only the 5 least significant bits are used for the program counter
Goto is not essential but if you use write h, be careful because the PC is incremented between each line so "write h n" will jump to the line n+1 and you'll have to do "write h 31" to jump to the line 0

simeks
Posts: 369
Joined: March 11th, 2015, 12:03 pm
Location: Sweden

### Re: Programmable computer

Coban wrote:I made an in-game 8bit programmable computer
This is very cool, nice work!
Instruction time is about 2M ticks, and I get it to run at about 0.4 instructions/s in Golly.
Here's a program to display the sequence of prime numbers (starting at 5 for simplicity):

Code: Select all

``````write e 2
write a 5
write b 3
move b c
write d 1
not a f
increment f
jumpif f
goto 24
sign f f
jumpif f
goto 16
increment d
goto 5
not d f
sign f f
jumpif f
goto 23
goto 3
print a
goto 2
``````
Pseudocode:

Code: Select all

``````    int tested = 5;

lab_6:
int divider = 3;

lab_5:
int sum = divider;
int sum_cnt = 1;

lab_4:
if (sum == tested)
goto lab_1;
if (sum > tested)
goto lab_2;

sum += divider;
sum_cnt++;
goto lab_4;

lab_2:
if (divider > sum_cnt)
goto lab_3;

divider += 2;
goto lab_5;

lab_3:
printf ("A prime number: %d\n", tested);
lab_1:
tested += 2;
goto lab_6;
``````

dvgrn
Moderator
Posts: 5887
Joined: May 17th, 2009, 11:00 pm
Contact:

### Re: Programmable computer

Impressive construction! Is it okay if I check it in to Golly's online archives? It certainly fits well in the Very Large Patterns category...!

If there's anything particular that should be included in the pattern comments, please post it here or let me know by PM. Otherwise I guess I can borrow something from the readme file.

gameoflifemaniac
Posts: 774
Joined: January 22nd, 2017, 11:17 am
Location: There too

### Re: Programmable computer

But can you post the same computer but programmed to display the sequence of prime numbers?
One big dirty Oro. Yeeeeeeeeee...

blah
Posts: 244
Joined: April 9th, 2016, 7:22 pm

### Re: Programmable computer

gameoflifemaniac wrote:But can you post the same computer but programmed to display the sequence of prime numbers?
I second this. I'm too lazy to get python to work, and I'm sure many others share this sentiment.
succ

Coban
Posts: 12
Joined: June 26th, 2016, 3:50 pm
Location: France

### Re: Programmable computer

Hi
@gameoflifemaniac: you can do it yourself, you just have to copy simeks's code into the assembly.py script then run it with golly
@blah: installing python is not difficult at all, you just have to download an installer and click... I am not with my computer these days so you can do it yourself I think...

dvgrn
Moderator
Posts: 5887
Joined: May 17th, 2009, 11:00 pm
Contact:

### Re: Programmable computer

Coban wrote:Hi
@gameoflifemaniac: you can do it yourself, you just have to copy simeks's code into the assembly.py script then run it with golly
@blah: installing python is not difficult at all, you just have to download an installer and click... I am not with my computer these days so you can do it yourself I think...
For people running Windows, installing Python is usually just a matter of picking the right installer, 32-bit or 64-bit, to match their version of Golly, and running it. There's not much else to do. Golly usually finds the python27.dll that it needs, without any further configuration.

That said, there are quite a few people who seem to have mysterious problems. 32-bit vs. 64-bit is the source of can't-run-Python problems more often than not -- along with the mistake of trying to install Python 3.x instead of 2.7.x with x != 11 ... But it seems as if there's something else that goes wrong on occasion.

I didn't have any trouble running the script. The resulting pattern is attached. Someone with a faster computer could maybe run it and make sure it performs as advertised...?
programmed_for_printing_primes.mc.gz
GOLComputer programmed with simeks' prime-generating code
programmed-prime_printer2.mc.gz
simeks' updated program for GOLcomputer -- prints first prime at 40M ticks instead of 50M ticks.

blah
Posts: 244
Joined: April 9th, 2016, 7:22 pm

### Re: Programmable computer

Thanks! I can confirm it works up to at least the second term, which is seven:
awholeprime.png (4.6 KiB) Viewed 20444 times
Unless there's some weird bug in Simeks' program, it works.
While you're at it, assemble this program:

Code: Select all

``````write a 1
xor a b a
goto 1``````
I just wrote it. It should simulate a 1D XOR rule (not rule 90 because that may take a while to simulate given how there's no shifts or rotates in the instruction set). I particularly want this because it would be a 1D CA in a computer in the game of life in a computer in real life.
succ

gameoflifemaniac
Posts: 774
Joined: January 22nd, 2017, 11:17 am
Location: There too

### Re: Programmable computer

Coban wrote:Hi
@gameoflifemaniac: you can do it yourself, you just have to copy simeks's code into the assembly.py script then run it with golly
@blah: installing python is not difficult at all, you just have to download an installer and click... I am not with my computer these days so you can do it yourself I think...
Remember! I did install Python, but it doesn't work.
One big dirty Oro. Yeeeeeeeeee...

Coban
Posts: 12
Joined: June 26th, 2016, 3:50 pm
Location: France

### Re: Programmable computer

Ok, sorry gameoflifemaniac,

gameoflifemaniac
Posts: 774
Joined: January 22nd, 2017, 11:17 am
Location: There too

### Re: Programmable computer

The printer does not print out primes! The squares don't change!
One big dirty Oro. Yeeeeeeeeee...

Coban
Posts: 12
Joined: June 26th, 2016, 3:50 pm
Location: France

### Re: Programmable computer

Ho... Strange, I don't remember having any issue with simeks's program.
Does it come from the computer ? Perhaps it is just very slow?

blah
Posts: 244
Joined: April 9th, 2016, 7:22 pm

### Re: Programmable computer

gameoflifemaniac wrote:The printer does not print out primes! The squares don't change!
Are you sure you're giving it long enough? The program presumably has to cycle a few times before displaying the first prime (it starts at 5, 101 in binary). And you are using the download dvgrn posted, right?
succ

gameoflifemaniac
Posts: 774
Joined: January 22nd, 2017, 11:17 am
Location: There too

### Re: Programmable computer

Sorry, I just wasn't waiting long enough!
One big dirty Oro. Yeeeeeeeeee...

Kiran
Posts: 284
Joined: March 4th, 2015, 6:48 pm

### Re: Programmable computer

It takes a bit over 50 million generations to start printing primes.
Kiran Linsuain

simeks
Posts: 369
Joined: March 11th, 2015, 12:03 pm
Location: Sweden

### Re: Programmable computer

Because of the recent interest, I wrote an updated version of the prime number program:

EDIT: Sorry, forgot the final change I made, updated below.

Code: Select all

``````write f 224
write g 2
write a 5
write b 3
write c 0
not a e
increment e
increment c
and d f e
jumpif e
goto 14
goto 8
jumpif d
goto 24
not c e
sign e e
jumpif e
goto 23
goto 4
print a
goto 3
``````
The innermost loop is optimized down from 9 to 5 instructions which improves speed a lot. It also works correctly up to the prime number 223 instead of 127 as the previous version.

To generate all prime numbers below 100, the computer must execute 7866 instructions. The cycle time is 2003880 ticks, so that's a total of 15762520080 generations.

With 64-bit Golly 2.8 with 12 GB of hash memory and a step size of 2^18 (8^6) it can reach about 1.2 instructions/s on my computer, so all prime numbers below 100 can be generated in less than 2 hours.

dvgrn
Moderator
Posts: 5887
Joined: May 17th, 2009, 11:00 pm
Contact:

### Re: Programmable computer

simeks wrote:Because of the recent interest, I wrote an updated version of the prime number program...
With 64-bit Golly 2.8 with 12 GB of hash memory and a step size of 2^18 (8^6) it can reach about 1.2 instructions/s on my computer, so all prime numbers below 100 can be generated in less than 2 hours.
Looks good! I've edited my post above to include the reprogrammed version as well. It displays the initial 5=101 binary, at only 40 million ticks now.

For those who don't like waiting even that long, here's the same programmed computer run up to 87.65M ticks, so the 5 has already been printed. The transition to printing 7=111 binary happens right around 88 million ticks

-- How come the 16 bit flickers on for a moment just before the 88M mark, by the way (starting at 87867000, gone by 87946000)? Looks like there's a leftover signal stream that hasn't quite been cleared yet when the "print" signal goes through -- but it cleans itself up very nicely.

The next prime doesn't get printed until 225M ticks. For what it's worth, on my old laptop with only 1.5GB to spare for Golly, it seems as if the pattern runs a bit more smoothly at a step size of 2^16 than 2^18.
Attachments
programmed-prime_printer2+87.65M.mc.gz
Prime printer version 2, primed to print 111 at T=87865000

blah
Posts: 244
Joined: April 9th, 2016, 7:22 pm

### Re: Programmable computer

You still haven't assembled the program I wrote, dvgrn. Spreaking of which, how would you calculate a logical (or arithmetic) right shift? A left shift is easy with addition, but what about a right shift? The computer has no shift or rotate opcodes.

I could imagine using an interative process f(n) to find the smallest number x*2>=n or something like that, but that would be impractically slow. Is there a faster way? Seems like coban forgot about shifts or ran out of opcode space or something.

If we figure that out, we can easily write programs for all the elementary CA.
succ

Coban
Posts: 12
Joined: June 26th, 2016, 3:50 pm
Location: France

### Re: Programmable computer

dvgrn wrote: -- How come the 16 bit flickers on for a moment just before the 88M mark, by the way (starting at 87867000, gone by 87946000)? Looks like there's a leftover signal stream that hasn't quite been cleared yet when the "print" signal goes through -- but it cleans itself up very nicely.
Does it continues to flicker after writing ?
I had some synchronisation problems with the printer when I was building the computer but normally the loops before the input of the printer should fix this kind of issues by synchronising the arriving of the data with the writing instruction signal.
Perhaps the loops aren't big enough, I'll try to fix it later...

Coban
Posts: 12
Joined: June 26th, 2016, 3:50 pm
Location: France

### Re: Programmable computer

Yes blah... I forgoted shifts...
There is enough space for 3 more instructions
I'll add them later, has I sad before I haven't my personal computer with me these days

gameoflifemaniac
Posts: 774
Joined: January 22nd, 2017, 11:17 am
Location: There too

### Re: Programmable computer

And is it possible to make it print primes starting from 2?
One big dirty Oro. Yeeeeeeeeee...

blah
Posts: 244
Joined: April 9th, 2016, 7:22 pm

### Re: Programmable computer

gameoflifemaniac wrote:And is it possible to make it print primes starting from 2?
That would be essentially trivial; just append some print instructions (assuming you have the space in memory). Maybe the loop could be started earlier, too.
succ

dvgrn
Moderator
Posts: 5887
Joined: May 17th, 2009, 11:00 pm