Composite
A small assembly language where every number is a prime. To say 72 you write 359, the 72nd prime.
ArthroStar11, 2021 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
ArthroStar11 made Composite in 2021. It has 26 registers, a stack of up to 1000 values and one flag that is true or false. The twist is in the numbers. Opcode n is written as the nth prime, and so is every argument, so a program is a column of primes. The specification says the name is a pun.
Read the story
There is no prime for 0. A program that needs 0 sets a register to 1 and subtracts it from itself.
The machine
| Opcode | Written | Does |
|---|---|---|
| 1 | 2 | Start a subroutine |
| 2 | 3 | Call a subroutine |
| 3 | 5 | Return |
| 4, 5 | 7 ... 11 | Loop while the flag is true |
| 6, 7, 8 | 13 17 19 | Flag becomes a > b, a = b, or its opposite |
| 9 to 13 | 23 29 31 37 41 | Add, subtract, multiply, divide or take the remainder, into a |
| 14, 15 | 43 47 | Push a register, pop into one |
| 16 | 53 | Set a register to a number, or copy another register |
| 17, 18 | 59 61 | Read a character or a number |
| 19, 20 | 67 71 | Print a character or a number |
Arguments are primes too. 53 2 2 359 is opcode 16 with 1, 1 and 72, which sets register 1 to 72. The main routine stops at the first subroutine, and subroutines are numbered from 1 in the order they appear.
Example
The HI puts 72 and 73 in registers 1 and 2 and prints them as characters.
The HI puts 72 and 73 in registers 1 and 2 and prints them as characters.
The specification counts down from 99 with a space after each number. This one starts at 5, the 5th prime being
- Register 3 holds 32, a space, and
19sets the flag before the loop.
The truth machine makes 0 as 1 minus 1, reads a number and prints it. If the number is more than 0, the loop calls subroutine 1, which prints it again for ever.
Patterns it teaches
- Encoding tricks: an ordinary machine behind a code of primes.
Further
See also
Stack-based
Write your own in Run Convert a program from Composite
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: composite.
Command line
shib run composite -e '53 2 2 359
53 2 3 367
67 2
67 3'shib manual compositeSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/composite.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org