OISC:2bis
Every instruction is two memory addresses. Their signs decide what the instruction is, and a decimal point makes one indirect.
2022 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
OISC:2bis is the second version of OISC:2, short for Obfuscated Indirect Subleq with Coprocessor, 2 word instruction. It starts from Subleq and pushes the idea that the instruction is hidden in the addresses as far as it goes. A word can be positive, negative or zero, and the two words of an instruction give nine combinations, so nine instructions. Writing an address as 50.0 instead of 50 makes it indirect. The specification asks where the instruction is, and the answer is nowhere in the executable code.
Read the story
This version adds a data stack with 46 stack instructions, a return stack, and an assembler with readable macros that leave no trace in the numbers.
The machine
[X] is the word at address |X|. All code is in positive memory; negative memory is reached only through an indirect address.
| A | B | Does |
|---|---|---|
| + | + | [B] = [B] - [A] |
| - | + | If [A] <= 0, jump to B |
| + | - | If [A] <= 0, call B |
| - | - | If [A] <= 0, jump by [B] from here |
| + | 0 | Push [A] |
| - | 0 | Pop into A |
| 0 | + | Run stack instruction [B] |
| 0 | - | If [B] <= 0, return |
| 0 | 0 | Halt |
Stack instruction 1 reads a character and -1 prints one, 2 reads a digit and -2 prints a number, and the rest are stack shuffles, bitwise logic and arithmetic up to atanh. The two that allocate and free memory, 16 and -16, are left out, as the specification does not say how they work.
The assembler macros are /sub /jump /call /relj /push /pop /exec /ret /halt, and a branch with one argument gets the automatic word ZERO as its test. The line % --NEGATIVE--: --NEGATIVE-- is mandatory; what follows it goes to addresses -1, -2 and down.
Example
The sample, as raw numbers.
The sample, as raw numbers. It prints a string from positive memory with a loop that steps up through memory, then one from negative memory with a loop that steps down. The specification also gives the same program in the assembler, and it lays down these 94 words exactly.
The first instruction -65 25 tests the word at 65, which is 0, and jumps to 25. The words 50.0 and -50.0 reach the string through the pointer kept at 50.
In the assembler, six times seven. /exec runs the stack instruction whose number is in the named word, 12 to multiply and -2 to print a number.
Patterns it teaches
- One instruction: Subleq with the opcode hidden in the signs of the addresses.
- Self-modifying code: code and data share one memory of words.
- Stack machines: the coprocessor is a stack.
Further
See also
OISC
Self-modifying
Write your own in Run Convert a program from OISC:2bis
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: oisc-2bis.
Command line
shib run oisc-2bis program.txtThe program is long; save it as program.txt first.
shib manual oisc-2bisSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/oisc-2bis.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org