Close

Native Brainfuck Loop Implementation on Dekatron Counters

A project log for DekatronPC

Silicon-free computer on vacuum and cold-cathode tubes with pure brainfuck instruction set

artem-kashkanovArtem Kashkanov 02/09/2018 at 12:380 Comments

On dekatron bi-directional counter we can do only Load/Store and Increment/Decrement operation I try to understand how can we implement native Brainfuck loops.

In brainfuck language Loops are marked with '[' and ']' instructions. If on executing ']' instruction current data value is not null - we should return to IP after '[' instruction.

Loops can be nested with very deep stack levels. So, let's first add Word-length register and store IP value of last '[' instruction:

If we execute ']' instruction and see, that our stored value is valid and we need to do next loop iteration - we just load this IP.

If we should fall through to the IP after ']', we go there and send invalidating signal to our cache value.

As a result if we need to go to the beginning of outerLoop we should find beginning IP value.

Let's add IpStack Counter. It's max value would be the limitation of max stack level. For example we can count from 0 to 1000 - just need 3 dekatrons, or 10 tiratrons (for tiratron counter).

So each loop end we increment Stack counter, and for loop beginnings - decrement it. And do IP decrement. When IpStack becomes to be zero it means that we found outerLoop beginning. We can load this IP to cache and start performing yet another iteration of the loop.

Discussions