Skip to content

Instruction Set

Supercolbat edited this page Jul 14, 2022 · 7 revisions

Note: Binary++ is in early development and these codes will likely change at least once.

Prefixes

The instructions are categorized by their function. Instructions in the same category share the same four-bit prefix.

Prefix Description
0000 General instructions
1000 Arithmetic
1100 Logic Gates
1110 Equality
1010 Conditionals
1001 Undecided

Instructions

Mnemonic Code Arguments Description
POP_STACK 00000001 Stack (1) Removes the value at the top of the stack.
PUSH_STACK 00000100 1 Pushes a value to the stack
PUSH_STRING_STACK 00000101 ... Joins the following arguments as a string until a null-terminator is reached.
PUSH_LONG_STACK 00000110 ... Pushes all codes as a one binary number until a null-terminator is reached.
LOAD_MEMORY 00000010 1 Loads the value at a memory address.
STORE_MEMORY 00000011 1 + Stack (1) Stores the top-of-stack value to a memory address.
DUP_TOP 00000111 None Duplicates the top-of-stack value.
READ_FROM 00001000 1 Reads from a stream and pushes the text to stack. 0 = STDIN; other reads from a stream in a memory address.
READ_CHAR_FROM 00001001 1 Reads one character from a stream and pushes the text to stack. 0 = STDIN; other reads from a stream in a memory address.
WRITE_TO 00001010 1 Writes the top-of-stack value to a stream. 0 = STDOUT; other reads from a stream in a memory address.
OPEN_FILE 00001100 1 + Stack (1) Opens a file from a path (top-of-stack) with specified mode.
MAKE_MARKER 00001110 1 Makes a marker at the current position and writes it the a memory address.
GOTO_MARKER 00001111 1 Goes to a marker. 0 as argument returns to the position fo the last GOTO_MARKER call.
BINARY_ADD 10000001 Stack (2) Pushes TOS1 + TOS2 to stack.
BINARY_SUBTRACT 10000010 Stack (2) Pushes TOS1 - TOS2 to stack.
BINARY_MULTIPLY 10000101 Stack (2) Pushes TOS1 * TOS2 to stack.
BINARY_POWER 10000110 Stack (2) Pushes TOS1 ** TOS2 to stack.
BINARY_TRUE_DIVIDE 10001001 Stack (2) Pushes TOS1 / TOS2 to stack.
BINARY_FLOOR_DIVIDE 10001010 Stack (2) Pushes TOS1 // TOS2 to stack.
BINARY_MODULO 10000100 Stack (2) Pushes TOS1 % TOS2 to stack.
BINARY_AND 11000001 Stack (2) Pushes TOS1 && TOS2 to stack.
BINARY_OR 11000010 Stack (2) Pushes TOS1 || TOS2 to stack.
BINARY_XOR 11000011 Stack (2) Pushes TOS1 ^ TOS2 to stack.
BINARY_NOT 11000100 Stack (2) Pushes ! TOS to stack.
BINARY_LEFT_SHIFT 11001000 Stack (2) Pushes TOS1 << TOS2 to stack.
BINARY_RIGHT_SHIFT 11001001 Stack (2) Pushes TOS1 >> TOS2 to stack.
EQUALS_TO 11100001 Stack (2) Pushes TOS1 = TOS2 to stack.
NOT_EQUAL_TO 11100000 Stack (2) Pushes TOS1 != TOS2 to stack.
LESS_THAN 11100010 Stack (2) Pushes TOS1 < TOS2 to stack.
LESS_EQUAL_THAN 11100011 Stack (2) Pushes TOS1 <= TOS2 to stack.
GREATER_THAN 11100100 Stack (2) Pushes TOS1 > TOS2 to stack.
GREATER_EQUAL_THAN 11100110 Stack (2) Pushes TOS1 >= TOS2 to stack.
IF_RUN_NEXT 10100000 1 + Stack (1) Runs the n number of instructions if the top-of-stack value is True. Otherwise, they are skipped.
SKIP_NEXT 10100001 1 Skips n number of instructions.
GO_BACK 10100010 1 Goes back n number of instructions.
FORWARD_ARGS 10010000 1 + Stack (n) Passes the n amount of arguments from stack to the next instruction where n is the passed argument.
ROT_TWO 10010001 Stack (2) Reverses the positions of the top two stack values.
ROT_THREE 10010010 Stack (3) Shifts the third and second stack values up one and moves the first one down to the third position. a, b, c -> c, a, b
IMPORT_MODULE 11110000 1 + Stack (1) Imports a module from a path (stack) into a frame (arg).
PUSH_STACK_MODULE 11110001 2 Pushes a value from memory in a module to stack.
GOTO_MODULE 11111000 2 Goes to a marker in a module.

The argument 00000000 is used for special functionality in some instructions. In turn, the 0th memory address cannot be used.

File modes (WIP)

Code Type Description
00000000 r Read mode
00000001 r+ Read and write mode
00000010 rb Read mode; bytes
00000011 rb+ ...
00000100 w Write mode
00000101 w+ Write mode; create file
00000110 wb Write mode; bytes
00000111 wb+ ...
00001000 a Append mode
00001001 a+ ...
00001010 ab Append mode; bytes
00001011 ab+ ...
00001100 x ...
00001101 x+ ...
00001110 xb ...
00001111 xb+ ...
Clone this wiki locally