TIS-100 Game Notes / Subroutines

I’ve been playing TIS-100, which is a puzzle programming game. It consists of interconnected nodes that have a single register (ACC) and one backup register (swappable-only, BAK). Each node is programmed individually and can communicate with each other through MOV instructions. They are all granted a subset of assembly:

  # ADDRESSABLES
  <SRC/DST> = LEFT, RIGHT, UP, DOWN the node in that direction
  <SRC/DST> = ANY                   any connected node
  <SRC/DST> = LAST                  the last node used by ANY
  <SRC/DST> = ACC                   this node's ACC register
  MOV <SRC>, <DST>                  sends SRC => DST

  # ARITHMETIC
  SUB <SRC>                         sets ACC => ACC-SRC
  ADD <SRC>                         sets ACC => ACC+SRC
  NEG                               sets ACC => -ACC

  # REGISTERS
  SAV - sets registers BAK=>ACC
  SWP - swaps registers BAK<=>ACC

  # GOTOS
  <LABEL> = a "goto" line marker, eg: "START:"
  JMP/JEZ/JGZ/JLZ <LABEL> - jump based upon ACC being any/equal-to-zero/greater-than-zero/less-than-zero
  JRO <SRC> - jump to an offset from current line, eg -1 will jump to previous instruction, 1 will jump to next instruction

During the game you are forced to create subroutines inside each node, since each node can only hold 15 lines of instructions. You must essentially call each subroutine by using the MOV instruction to pass messages between nodes.

I wanted to note down the subroutines as I create them in the game for my own use as well as anyone else that is interested.

CMP Subroutine

Takes in two arguments (a, b) from source and compares them.

START:
MOV ANY, ACC # A
SUB LAST # B
JEZ EQUAL
JLZ LESS
MOV 1, LAST # A>B
JMP START
EQUAL:
MOV 0, LAST # A=B
JMP START
LESS:
MOV -1, LAST # A<B

ABS Subroutine

Takes in a single argument, returns the absolute value of the argument.

START:
MOV ANY, ACC
JLZ NEG
MOV ACC, LAST
JMP START
NEG:
NEG
MOV ACC, LAST

DELTA Subroutine

Takes in two arguments, returns the delta between the two arguments.

MOV ANY, ACC
SUB LAST
MOV ACC, <ABS_NODE>
MOV <ABS_NODE>, LAST

Comments