TIS-100 Hacker's Guide

Assembly

See Also

Speed

The TIS-100 runs at 50 Hz in RUN mode, 5,000 Hz in FAST mode, and 25 Hz when the STEP key (F6) is held down. (Holding the STEP button down only runs a single step.) Most assembly instructions run in a single cycle; MOV takes two cycles under some circumstances.

Overall Node Behavior

The behavior of using ANY as a destination suggests that nodes are evaluted starting at the upper left, moving left to right, and advancing down one row and returning to the left edge upon reaching the end of a row. This behavior is not guaranteed and may change.

Comments

The character # and any characters after it on a line are ignored. Comments may follow a label or opcode and arguments.

Characters following ## are treated as the program's title and are displayed in the menu. The ## does not need to be the start of comment. Spaces one the left and right side of the title are discarded. If multiple entries with ## are present, TIS-100 searches starting in the upper left node, searching from top to bottom inside of the node's assembly. If nothing is found, TIS-100 moves from left to right and repeats the search for the assembly in each node. Upon reaching the right edge, TIS-100 moves to the left of te next row down and repeats the procedure.

Title is "B":

# A ## B

Title is "#### C ####":

###### C ####

Title is "D":

##D

Title is "D":

##        D

Labels

A label, if present, must be the first thing on the line. It is terminated with a : which must be immediately adjacent to the label. Valid characters for labels are the letters A through Z, the digits 0 through 9, and the punctuation in the set of ~`$%^&*()_-+={}[]|\;'"<>,.?/ . There are no limitations on which characters may be in which positions of the label. A line may only have a single label. A label must have at least one character before the colon. Labels may be up to 18 characters long, but the longest addressable label is 14 characters.

Storage

ACC - Accumulator. Register. Can be used as a source or destination. Initialized to 0. Reads and writes are instantaneous.

BAK - Backup. Register. Only SAV and SWP interact with BAK. The identifier “BAK” is never a valid identifier in a program.

NIL - Nothing. Register. Can be used as a source, in which case “0” is returned. Can be used as a destination, which which case the value is discarded.

UP, DOWN, LEFT, RIGHT - Connections to adjacent nodes. Ports. Can be used as a source or a destination. When used as a destination, the value cannot be read by the adjacent node in the same cycle that it was written to. Blocks until a destination value is used as a source by the adjacent node or a source is used as a destination by an adjacent node.

ANY - Port. Can be used as a source, in which case the value will be read from the first port with a waiting value, as searched in the order LEFT, RIGHT, UP, DOWN. Can be used as a destination, in which case the value is available to all ports; it will be cleared from all ports as soon as any adjacent node reads it. Assuming all adjacent points try to read simulataneously, the winner will be selected in the order UP, LEFT, RIGHT, and DOWN. The search order is not formally part of the TIS-100 description, so it may change in future releases.

LAST - Port. Refers to the same port used by the last reference to ANY, either in read or write. If ANY has not been used, attempts to use LAST as a source will return 0, while attempts to use LAST as a destination will block forever.

source can be ACC, NIL, UP, DOWN, LEFT, RIGHT, ANY, LAST, or an integer from −999 through 999, inclusive. If the value is an integer, it is used directory. Otherwise the register or port is read for the value to use.

destination can be ACC, NIL, UP, DOWN, LEFT, RIGHT, ANY, or LAST.

Opcodes

Each opcode has 0, 1, or 2 arguments. The opcode and arguments must be separated by at least one space or comma, but may be separated by any number of spaces or commas. The following are all equivalent:

MOV 1 ACC
MOV,1 ACC
MOV 1,ACC
MOV,,,,1,,,,ACC
MOV , ,1, , ACC

NOP - No Operation - 1 cycle

Syntax: NOP

Does nothing.

MOV - Move - 1-2 cycles

Syntax: MOV source destination

Reads a value from source and write it to destination. If source is a port, blocks until a value is present. If destination is a port, blocks until the value is received.

1 cycle when writing ACC or NIL.

2 cycles when writing to UP, DOWN, LEFT, or RIGHT, assuming the neighboring node is willing to retrieve the value on the second cycle. The data is not yet in the port until the end of the first cycle. This prevents a single value from travelling multiple nodes in a single cycle.

SWP - Swap - 1 cycle

Syntax: SWP

Swaps the values of ACC and BAK

SAV - Save - 1 cycle

Syntax: SAV

Copies the value of ACC to BAK

ADD - Add - 1 cycle

Syntax: ADD source

The source value is added to the value in ACC, and the result placed in ACC. Results greater than 999 are limited to 999. Results less than −999 are limited to −999.

SUB - Subtract - 1 cycle

Syntax: SUB source

The source value is subtracted to the value in ACC, and the result placed in ACC. Results greater than 999 are limited to 999. Results less than −999 are limited to −999.

NEG - Negate - 1 cycle

Syntax: NEG source

The value in ACC is negative (swapped between positive and negative) and written back into ACC. 0 is left unchanged.

JMP - Jump - 1 cycle

Syntax: JMP label

Transfer execution to the first instruction after label.

JEZ - Jump if equal to zero - 1 cycle

Syntax: JEZ label

If the ACC is 0, transfer execution to the first instruction after label.

JNZ - Jump if not equal to zero - 1 cycle

Syntax: JNZ label

If the ACC is not 0, transfer execution to the first instruction after label.

JGZ - Jump if greater than zero - 1 cycle

Syntax: JGZ label

If the ACC is greater than 0, transfer execution to the first instruction after label.

JLZ - Jump if less than zero - 1 cycle

Syntax: JLZ label

If the ACC is greater than 0, transfer execution to the first instruction after label.

JRO - Jump relative offset - 1 cycle

Syntax: JRO source

Transfer execution to the offset specified by source. Offset is measured in instructions. Negative offsets can be used to move jump backward, positive offsets to jump forward, or 0 to execute the JRO instruction again.

HCF - Reboot

Syntax: HCF

Causes the game to restart. Halt and Catch Fire. As execution of this instruction terminates the active run, it cannot be used in a puzzle solution.