Skip to content

“TIS-100” – SEQUENCE COUNTER (SEGMENT 31904)

TIS-100 index

Solution for the NO_BACKUP achievement of not using the SWP instruction to access the BAK register:

full solution

The hard part of this achievement is that the units that accumulate the sequence sum and the input count need to be told when to output their results, but we can’t read in a signal value and jump conditionally on that without clobbering ACC.

However, if we assume that the running total will never be 999 and no inputs are negative (which may not be safe assumptions…), then what we can do is pass -999 to both units when we want them to output their results; when they add that, their accumulators will go negative, and we can check that easy peasy. Of course, before they send their numbers out, they both need to add 999 back in!

Interestingly, this alternate strategy also runs faster than my real solution that does use SWP, 271 cycles vs. 308…