Exapunks Cheat Sheet

⚠️ This page is a Work in Progress

Registers

Exas have 4 accessible registers:

REGDescription
XGeneral-purpose storage, stores a number or keyword
TAlso a general-purpose register, however TEST writes to this register, and TJMP and FJMP also read from this register
FRefers to an exa's held file. Reading from or writing to F advances the "file cursor" by one. Writing to F will overwrite a value unless the cursor is at the end of the file
MUsed for communication (locally or globally) between Exas. Reading and writing to this register will cause the Exa to wait for another Exa to either write or read the M register too

Hardware registers starting with # can also be accessed when an Exa is in the same node

Instructions

INSTSyntaxDescription
NOOPNOOPA no-op
NOTENOTE [...]A comment line, ; also works
COPYCOPY {REG/NUM} {REG}Writes value of {REG/NUM} to {REG}
ADDIADDI {REG/NUM} {REG/NUM} {REG}Adds the first {REG/NUM} to the second and writes it to {REG}
SUBISUBI {REG/NUM} {REG/NUM} {REG}Subtracts the first {REG/NUM} from the second and writes it to {REG}
MULIMULI {REG/NUM} {REG/NUM} {REG}Multiplies the first {REG/NUM} by the second and writes it to {REG}
DIVIDIVI {REG/NUM} {REG/NUM} {REG}Divides the first {REG/NUM} by the second and writes it (rounded) to {REG}
MODIMODI {REG/NUM} {REG/NUM} {REG}Divides the first {REG/NUM} by the second and writes the remainder to {REG}
RANDRAND {REG/NUM} {REG/NUM} {REG}Generates random number between the first {REG/NUM} and the second and writes to {REG}
SWIZSWIZ {REG/NUM} {REG/NUM} {REG}Takes first {REG/NUM} and uses second as a mask to generate a "Swizzled" value (more details below), writes to {REG}
TESTTEST {REG/NUM} {=/>/<} {REG/NUM}Compares the two input values and writes to register T (1 if true, 0 if false)
TEST MRDChecks if Exa could read from another Exa without waiting, and writes to register T
TEST EOFChecks if file cursor is at the end of the held file, and writes to register T
MARKMARK {LABEL}Sets a label (pseudo-instruction)
JUMPJUMP {LABEL}Jumps to {LABEL}
TJMPTJMP {LABEL}If T != 0, jumps to {LABEL}
FJMPFJMP {LABEL}If T == 0, jumps to {LABEL}
REPLREPL {LABEL}Creates a copy of this Exa (including location and registers, but not file), starting execution from {LABEL}
HALTHALTTerminates Exa and drops held file
KILLKILLTerminates other Exa, random but prioritises own Exas
LINKLINK {REG/NUM}Moves through link with ID of {REG/NUM}
HOSTHOST {REG}Copies hostname to {REG}
MODEMODEToggles M register between global and local
VOIDVOID MDiscards value from M
MAKEMAKECreates and grabs a new file
GRABGRAB {REG/NUM}Grabs file with ID of {REG/NUM}
FILEFILE {REG}Copies held file ID into {REG}
SEEKSEEK {REG/NUM}Moves file cursor by {REG/NUM}, clamped between start and end of file (-9999 and 9999 will reliably get you to the start and end of a file)
VOIDVOID FRemoves value in F where file cursor is pointing
DROPDROPDrops held file
WIPEWIPEDeletes held file

Macros

Macros are shorthand for writing repeating statements starting with @REPL N (N being the number of loops) and ending @END, within a macro, @{X,Y} can be used, X being the first value used, and Y being the amount added to X on each loop, so @{0,3} would be 0 on loop 1, 3 on the seconds, 6 on the third and so on. These can be used in label names too, which can be combined with testing and jumping to certain labels.

NOTE: Macros are not actual loops and can result in more instructions than a "real" loop

Swizzling

The mask digits represent a reversed index (from 1) of the input number (so 4321 will return the input number), and 0 will always give a 0. A negative mask will produce a negative number (or positive if input is negative).

INMASKOUT
678943216789
678912349876
678933337777
678912119899
6789-4321-6789
-6789-43216789
678920008000
678900010009

Highway Signs

When writing to highway signs, it takes 3 values to write a character to a highway sign:

  • 0-indexed row,
  • 0-indexed column,
  • then the character.

TOP TIP: when looping through a message, you can get row by dividing x by row length, and column by modulo-ing by row length.

Last edited on: 10th Feb 2022