miscmisc2
miscmisc2 is a low-level esolang made by User:Transoptimal with the goal of making a language that both isn't too inconvenient to use, and has a small set of instructions.
Memory
The memory is an array of integers that starts at index 0 and extends infinitely in the positive direction.
The value stored in the first memory cell is called the pointer, or P for short.
Input and output handling is implementation-specific. A reasonable default choice might be using a queue for input and a stack or text string for output.
Execution
To prepare a program to be executed:
- Write the number 0 to every memory cell.
- Write the program's source code to the memory, starting at index 0.
The execution cycle consists of these steps:
- If P is less than 1, or all the cells with an index greater than or equal to P contain the number 0, halt execution.
- The instruction stored in the cell at P (that is, the instruction pointed to by the pointer) is executed.
- If step 2 did not change P, P is incremented by 4.
Instructions
The instructions are written as their corresponding Unicode characters, with their character codes in parentheses, for convenience. (This is also how they were chosen.)
For explaining the instructions, the symbols A, B, and C will be used to represent the cells at index P plus 1, 2, and 3, respectively.
! (33) - Write the value of A, to the cell pointed to by B. Increment P by 3. & (38) - Write the value of the cell pointed to by A, to the cell pointed to by B. Increment P by 3. + (43) - Add the values of A and B, and write the result to C. - (45) - Subtract the value of B from the value of A, and write the result to C. ? (63) - If the value of A is positive, set P to the value of B. If the value of A is negative, set P to the value of C. . (46) - Read the next input value and write it to A. Increment P by 2. , (44) - Write the value of A to the output. Increment P by 2.
All other instructions are no-op.
Examples
Hello world
1 44 72 44 101 44 108 44 108 44 111 44 32 44 119 44 111 44 114 44 108 44 100 44 33
Outputs "Hello world!" in character codes.
Replacing numbers whose corresponding character is non-whitespace with that character, this is:
1 , H , e , l , l , o , 32 , w , o , r , l , d , !
cat
1 46 0 38 2 17 38 2 10 63 0 16 13 33 0 0 44 0 33 1 0
Assuming that the input implementation treats nonexistent inputs as the number 0, this outputs the entire input, then exits.
Replacing numbers that are instructions and not no-op with their corresponding characters, we get:
1 . 0 & 2 17 & 2 10 ? 0 16 13 ! 0 0 , 0 ! 1 0
Truth-Machine
A truth-machine is implemented in the following:
1 46 0 38 2 10 38 2 12 44 0 63 0 9 0
Interpreter
- Common Lisp implementation of the miscmisc2 programming language.