TIS-100, part 3

More fake assembly programming with TIS-100!

Segment 40196: signal pattern detector

Not the most optimal solution here (if the histograms are to be believed), but one that is easy to understand, with a clear separation of concerns between the nodes. The first node keeps track of how many sequential zeros it has seen, resetting the count if a non-zero value is found. It passes this value to the second node, which then checks if this value is at least 3. If so, it outputs one. If not, zero is outputted.

Segment 41427: sequence peak detector

I like this solution. It feels clean somehow, even though it's not the most efficient.

The input node acts as a controller for the min/max accumulator nodes. We use the JRO relative offset jump instruction to have the input node tell the accumulator nodes to switch between accumulate or output mode. Both accumulator nodes work the same way. In accumulate mode, they simply take the next value, compare it with the previous one, and store it if it's smaller/larger. In output mode, the value from ACC is passed down and the node resets itself by moving a large/small value into ACC.

Note that we don't use SAV or SWP at all. Everything is done using ACC only, which always contains the current best value. The accumulator nodes SUB the new value. Dependent on whether the result is smaller/larger than zero, we can then either MOV the new value into ACC to store it, or ADD the new value to get the old value back.

Segment 42656: sequence reverser

A gentle introduction to the stack memory node. We have to reverse the input sequences we receive, which stack memory happens to be perfect for. Two stack memory nodes are provided, though we'll only be using one.

The input node first places a zero on the stack, followed by the input sequence. It then signals (using the NIL special value/register) the next node that reading the input sequence has finished. The output node simply reads the values from the stack, which automatically puts them in reverse order, and outputs them. Once it has read the final zero from the stack, it signals back to the input node that the next sequence can be read, and the whole thing starts over again.

Segment 43786: signal multiplier

Here we have to multiply some values. If we were playing SHENZHEN I/O we could have just used the MUL instruction for this, but TIS-100 takes place in a simpler time, before all that newfangled Chinese computer chip doo-dah.

Anyway. This lack of a decent instruction set forces us to break down multiplication into its simpler form: repeated addition. In my solution, the A input node provides the value that gets added, while the B input node keeps count of how many times to add. Super simple stuff.