miscmisc2
Seven instructions in a row of integers. The program sits in memory, and its first cell says where to run next.
Transoptimal · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Transoptimal made miscmisc2 to be a low-level language that is not too awkward to use and still has a small set of instructions. Memory is a row of integers from cell 0 onwards. The program is written into it from cell 0, and cell 0 itself is the pointer P. So the first number of a program says where it starts, and a jump is a write to cell 0.
Read the story
Each instruction is a number, picked as the code of a character. ! is 33, & 38, + 43, - 45, ? 63, . 46 and , 44. Every other number does nothing.
The machine
A, B and C are the three cells after P.
| Instruction | Does | P moves |
|---|---|---|
! 33 | Write A into the cell B points to | 3 |
& 38 | Copy the cell A points to into the cell B points to | 3 |
+ 43 | Write A plus B into C | 4 |
- 45 | Write A minus B into C | 4 |
? 63 | Jump to B if A is above 0, to C if A is below 0 | 4 |
. 46 | Read the next input into A | 2 |
, 44 | Print A | 2 |
P moves on only when the instruction left it as it was. The machine halts when P is below 1 or every cell from P on is 0. The specification leaves input and output open. In this implementation input is bytes, the end of the input reads as 0, and , prints the character with A's code.
Example
Hello world.
Hello world. P starts at 1, and each 44 prints the number after it.
The specification also writes it with characters for the numbers. A token of one character other than a digit is read as its code.
The cat reads a byte into cell 2. Two & copy it into the ? and into the , further on, so the program rewrites its own operands. When the byte is above 0 it is printed, and ! 1 0 writes 1 into cell 0, which jumps back to the start. The end of the input reads as 0, and then ! 0 0 sets P to 0, which halts.
The truth machine works the same way. On the number 0 it prints 0 once and halts; on 1 it prints 1 forever.
Patterns it teaches
- Self-modifying code:
&copies values into the operands of later instructions. - Code as data: the program and its variables share one memory, and the pointer is a cell of it.
Further
See also
Cell-based
Write your own in Run Convert a program from miscmisc2
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: miscmisc2.
Command line
shib run miscmisc2 -e '1 46 0 38 2 10 38 2 12 44 0 63 0 9 0' --input '