Right at the start of these tutorials we built some timers. Now we’re going to upgrade them using our lessons on state and interaction.
With this timer, we represent the current time using the marble’s position on its track. This wastes a lot of space — for a timer that with just 10 different states, we have to use up 12 cells.
But wait! We know a more compact way to represent a number:
This register can store 26 = 64
different values. By representing the current time as a base 2 integer, we can count up to 64 steps in a smaller space than our 10-step timer.
Even better, if we increase the height of our register by just a single row, we double the number of states we can represent. A register 2 disks in height could store 216 = 65,536
distinct values!
incrementing the register
So how do we convert this into a timer?
To update the current time, we want to increment (add 1 to) the current value in the register.
Therefore, our plan is to:
- Create a stream that sends the value
1
on repeat, i.e. 000001 000001 000001 … - Connect the register and this stream up as inputs to an adder
- Connect the output of the adder back into the register
Notice that our initial timers measured steps, while this new timer measures words
— i.e. it counts how many complete cycles of data have passed in the stream.
Now we have a compact, efficient timer, we’re going to use it to upgrade our memory.
continue