AddSubJump
One instruction. It adds or subtracts, depending on a fourth cell, and always jumps.
PKMN Trainer · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
PKMN Trainer made AddSubJump, or ASJ, after FlipJump, BitBitJump and Subleq. There is only one instruction, so its name can be left out. Four numbers in a row are an instruction.
Read the story
ASJ a b c d if cell d > 0, cell a -= cell b, else cell a += cell b; then jump to c
The program sits in the same memory it works on, so an instruction can change its own operands. With cells of any size the specification says it can run a Minsky machine, so it is Turing complete.
The machine
| Address | Name | Holds |
|---|---|---|
| -1 | IO | Input when read, output when written |
| -2 to -5 | CF ZF NF VF | The carry, zero, negative and overflow flags, read only |
| -6 -7 -8 | @1 @0 @n1 | The constants 1, 0 and -1, read only |
| -9 | FUM | 0 stops the flags from changing |
A jump to any of these addresses halts. The assembler fills in short lines. A B C becomes A B C -7, which always adds because cell -7 holds 0, and A B becomes A B ? -7, where ? is the address of the next instruction. name: labels a cell, .data makes a line raw cells, and def makes a macro.
Cells hold whole numbers of any size, so carry and overflow never happen. Input and output are bytes.
Example
The label example.
The label example. @A is cell 4, which holds 65. The first instruction adds it to IO, which prints A, and jumps to -1.
Each -1 X line prints one data cell and goes on to the next line. The last one jumps to -1.
A macro named macro. The line @0 @0 @0 adds 0 to a constant and jumps to -7, which halts.
The specification's Hello World and truth machine call macros from its library, CMP and IFZ. IFZ uses a cell four that the specification never defines, and JMP uses zero, which is only a label inside IFZ. So those two do not run as written.
Patterns it teaches
- One instruction: add or subtract by a sign test, then jump.
- Self-modifying code: the Hello World walks through its text by adding 1 to an operand of its own first instruction.
Further
See also
Works-in-Progress
OISC
Write your own in Run Convert a program from AddSubJump
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: addsubjump.
Command line
shib run addsubjump -e 'def macro A {
IO A
}
macro H
@0 @0 @0
H:.data 72'shib manual addsubjumpSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/addsubjump.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org