Skip to content

Instantly share code, notes, and snippets.

@aaronryank
Last active September 8, 2018 14:47
Show Gist options
  • Save aaronryank/2806c4ce8a3602c6cae6c18e52fcfe63 to your computer and use it in GitHub Desktop.
Save aaronryank/2806c4ce8a3602c6cae6c18e52fcfe63 to your computer and use it in GitHub Desktop.

Subtract and branch if less than or equal to zero (SUBLEQ)

Subtract the contents of address a from the contents of address b, store the result in address b, and if the result is non-positive, transfer control to address c. If the result is positive, execution continues to the next instruction in the code. So subleq a, b, c would be equivalent to:

mem[b] -= mem[a];
if (mem[b] <= 0)
    goto c;

A variant of subleq is subneg, which is equivalent to subleq except instead of mem[b] <= 0 it performs mem[b] < 0.

Reverse subtract and skip if borrow (RSSB)

  • The accumulator is subtracted from the specified memory location.
  • The next instruction is skipped if the memory location was less than the accumulator.
  • The result is stored in the accumulator and the memory location.

Memory location 0 contains the program counter (aka instruction pointer), and memory location 1 contains the accumulator.

RSSB x is equivalent to:

if (mem[x] < mem[1])
   skip_next_instruction();
mem[x] -= mem[1];
mem[1] = mem[x];

Another example is a one-instruction variant of [transport triggered architecture][3].

@Reconcyl
Copy link

Reconcyl commented Feb 9, 2018

ais's Three Star Programmer is another example of one of these. ais claims it's Turing-complete, and I'm inclined to believe him.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment