CatCompiler.dev

The cat compiler.

Hi! I like cats, computers and compilers and I sometimes write blog posts.

TIS-100 is a Video Game


It doesn’t sound like it but TIS-100 is a video game, not some technology. Today I would like to discuss it in the context of programming. It has some interesting game-play mechanics that are very similar to programming. Today, I’d like to introduce you to it!

The Introduction of the Introduction

TIS-100 is game by Zachtronics, In this game you solve problems with a very simple low-level language. Here is what the second level looks like.

Let’s jump right into the task! So we have to take the values and output them, it’s rather simple but – no no don’t go I promise it gets interesting yet. This is an introductory problem and it does a very good job of introducing you to the game-loop and why it is fun, it may look simple but there’s some snag you run into pretty quickly. The problems aren’t in themselves very complicated but the means you have to solve them are very primitive.

The TIS-100 Abstract Machine

If you look closely at the image above, you will see that there is a grid of machines, this is your biggest advantage and most interesting part of the game. Every task we do must be broken down into very small parts. The language you have to do it in is also very simple, let’s jump into the most common instructions!

InstructionSummary
MOV source, destinationmove a value from the source register to the destination register
ADD inputadd a value
SUB inputsubtract a value
JMPjump to a part of the code
JNZ, JEZ, JLT, JGTjump to a part of the code when a condition is met

That’s literally all of the instructions you need! For some extra ones for optimizations and complex logic, check the TIS-100 documentation. Now, let me detail the most common registers (and pseudo-register).

RegisterSummary
UP, RIGHT, DOWN, LEFTThe value at the given side
NILzero, or nothing
ACCaccumulator / counter. SUB and ADD modify this value and the conditional jumps check this value.

And again, that’s about it! There are a few more but this is 90% of the functionality you need to solve many of the game’s challenges – isn’t it refreshing having such a straightforward language to work with. The final details I’d like to add is that # is used for comments and name: is used for comments.

Here’s some example snippets.

# Move a value from the machine above 
# to the machine below
MOV UP, DOWN
# Discard a value from the machine left
MOV LEFT, NIL
# Go in an infinite loop
LOOP:
JMP LOOP
# loop for 5 iterations
MOV 5 ACC # SET ACC TO 5
LOOP:
  SUB 1
  JEZ END
  JMP LOOP
END:
# add the inputs from top and left
MOV ACC, UP
ADD LEFF

Some further nuances are as follows:

  • When the machine reaches the end of the code, it goes back to the start
  • The snippets above are not complete programs, you will need to add more to make them useful
  • When the machine starts, ACC is set to zero
  • Machines will wait until the sides have pushed and pulled their values, that is to say it uses blocking IO
  • Integers cannot go bellow -999, or above 999.
  • There are additional instructions not listed here that one may use. Check the manual!

So given how straightforward the language is, where is the challenge? Well, let me introduce you to the further constraints. This is what gives the game an edge despite the simple and elegant design. Without these further constraints, the game may be too easy.

Further Constraints

The following constraints make the game challenging

  • Each level has a fixed small count of machines you can program, you must make the program simple enough to divide over 12 machines or less, taking into account their adjacency.
  • Each machine allows for exactly one small program, this program is a max of 18 characters wide by 15 characters tall.
  • IO overhead of 2 cycles– every input and output from a machine takes a mi minimum of 2 cycles.
  • There is only one hardware register to use the very minimal instructions with.
  • There are leader-boards for instruction count, machine count and cycle count, this gives a huge incentive to make hyper-optimized solutions.

To Do

In the next article, I will build on this base and document very useful patterns I have found in this game. It will be major spoilers, play it now before it’s too late! Thanks for reading.


2 responses to “TIS-100 is a Video Game”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.