GByC is a simple bytecode concept. This page was created to explain GByC and to offer a FLOSS reference implementation of GByC, called GByCI.
One GByC instruction consists of its identifier, a length identifier n and up to n instruction arguments. Look at this example for the PUSH instruction:

As you can see, every position on the GByC Stack is 16 Bit (2 Byte) long. This means you are allowed to write onto 65,536 "cells". [The GByCI implementation uses int32_t for every cell. Consequently, the range for each cell is -2,147,483,647 to 2,147,483,647.]
All instructions are explained below.
GByCI 0.8 (Written in C)
GByCI 0.8 (Win32 Binary, Compiler: tcc by Fabrice Bellard)
License: BSD-like license (see source code)
Example:
| Identifier | 1 |
| Length identifier n | > 2 |
| Byte 1 & Byte 2 | Rewind to this position before pushing |
| Bytes …n | to be pushed |
| Feature | Push n chars onto Stack |
Example:
| Identifier | 2 |
| Length identifier n | > 2 |
| Byte 1 & Byte 2 | Rewind to this position before pushing |
| Byte 2 & Byte 3 | to be pushed ((B2 << 8) | B3) |
| Byte 4 & Byte 6 | to be pushed ((B4 << 8) | B5) |
| … | … |
| Feature | Push (n-2)/2 16-bit ints onto Stack |
Example:
| Identifier | 4 |
| Length identifier n | = 0 |
| Feature | Print Stack on stdout, assuming every Stack byte is one char |
| Identifier | 8 |
| Length identifier n | = 2 |
| Byte 1 & Byte 2 | Pseudo-Pointer to JUMP registry |
| Feature | Write current file position (ftell()) to JUMP registry |
| Identifier | 9 |
| Length identifier n | = 6 |
| Byte 1 & Byte 2 | Pseudo-Pointer to JUMP registry |
| Byte 3, Byte 4, Byte 5, Byte 6 | Pointer to bytecode position (max. 4GiB) |
| Feature | Write file position (given in B3-B6) to JUMP registry |
| Identifier | 10 |
| Length identifier n | = 2 |
| Byte 1 & Byte 2 | Pseudo-Pointer to JUMP registry |
| Feature | Jump to index (B1-B2) in JUMP registry; register JUMP #65535 with current file position (ftell()) |
| Identifier | 12 |
| Length identifier n | = 6 |
| Byte 1 & Byte 2 | If condition 1, must be on Stack |
| Byte 3 & Byte 4 | If condition 2, must be on Stack |
| Byte 5 & Byte 6 | Pseudo-Pointer to JUMP registry |
| Feature | Compare Stack{B1-B2} with Stack{B3-B4}; if equal, JUMP to B5-B6 in JUMP registry (register JUMP #65535 with current ftell()). If not, proceed. |
| Identifier | 13 |
| Length identifier n | = 6 |
| Byte 1 & Byte 2 | If condition 1, must be on Stack |
| Byte 3 & Byte 4 | If condition 2, must be on Stack |
| Byte 5 & Byte 6 | Pseudo-Pointer to JUMP registry |
| Feature | Compare Stack{B1-B2} with Stack{B3-B4}; if not equal, JUMP to B5-B6 in JUMP registry (register JUMP #65535 with current ftell()). If, proceed. |
| Identifier | 14 |
| Length identifier n | = 6 |
| Byte 1 & Byte 2 | If condition 1, must be on Stack |
| Byte 3 & Byte 4 | If condition 2, must be on Stack |
| Byte 5 & Byte 6 | Pseudo-Pointer to JUMP registry |
| Byte 7 & Byte 8 | Pseudo-Pointer to JUMP registry for ELSE |
| Feature | Compare {B1-B2} with {B3-B4}; if equal, JUMP to B5-B6 in JUMP registry (register JUMP #65535 with current ftell()). If not, JUMP to B7-B8 (register JUMP #65535 with current ftell()). |
| Identifier | 22 |
| Length identifier n | = 6 |
| Byte 1 & Byte 2 | Stack position |
| Byte 3 & Byte 4 | Stack position |
| Byte 5 & Byte 6 | Stack position |
| Feature | {B5-B6} will contain the result of the {B1-B2}+{B3-B4} addition. |
| Identifier | 24 |
| Length identifier n | = 6 |
| Byte 1 & Byte 2 | Stack position |
| Byte 3 & Byte 4 | Stack position |
| Byte 5 & Byte 6 | Stack position |
| Feature | {B5-B6} will contain the result of the {B1-B2}+{B3-B4} subtraction. |
| Identifier | 26 |
| Length identifier n | = 4 |
| Byte 1 & Byte 2 | Stack position |
| Byte 3 & Byte 4 | Stack position |
| Feature | {B3-B4} will be the result of the {B1-B2} negation (equal to {B1-B2}*-1). |
| Identifier | 254 |
| Length identifier n | = 2 |
| Byte 1 & Byte 2 | 16-bit return value |
| Feature | Set return value to B1-B2. |
Example 1: gbyci_1.bc Print a string
mgod output:
1 6 0 0 77 82 80 71 1 3 0 4 33 4 0 254 2 0 0
Example 2: gbyci_2.bc Repeats a string
mgod output:
1 3 0 13 8 1 3 0 14 1 8 2 0 0 1 6 0 0 77 82 80 71 4 0 24 6 0 13 0 14 0 13 13 6 0 13 0 14 0 0 254 2 0 0
Example 3: gbyci_3.bc Prints all printable ASCII chars
mgod output:
1 3 0 0 33 1 3 0 14 1 1 3 0 15 127 8 2 0 0 4 0 22 6 0 0 0 14 0 0 13 6 0 0 0 15 0 0 254 2 0 0