MBX1 executable format
The file header and opcode encoding for bytecode ABI 1.
Header
| Byte offset | Length | Value |
|---|---|---|
| 0 | 4 | ASCII MBX1. |
| 4 | 2 | Bytecode ABI, 1. |
| 6 | 2 | Flags, 0. |
| 8 | 2 | Total file size, including header. |
| 10 | 2 | Variable count, 26. |
| 12 | 2 | Operand-stack limit, 16. |
| 14 | 2 | Reserved, 0. |
Words are little-endian. The minimum accepted executable length is 17 bytes: the header and at least an instruction byte. The file-data checksum is the MKS2 inode checksum, not a field in this header. The entire file is checked before execution.
Encoding
Each opcode is one byte. Variable operands are zero-based, A=0 through Z=25. Immediate word operands and branch offsets are little-endian. Branch offsets count from the start of the file, so executable targets must be at least 16 and less than the total size.
LINE is an internal source-line marker used for error reporting; the source-language drawing LINE compiles to DRAW. KEY implements INKEY. STRING and PATH carry a length byte followed by data. All other opcodes have no inline operand unless listed below; their arguments come from the operand stack.
Opcode index
| Decimal | Hex | Mnemonic | Inline operand |
|---|---|---|---|
| 0 | 00 | END | None |
| 1 | 01 | LINE | u16 source-line marker |
| 2 | 02 | CONST | u16 bit pattern |
| 3 | 03 | LOAD | u8 variable index |
| 4 | 04 | STORE | u8 variable index |
| 5 | 05 | ADD | None |
| 6 | 06 | SUB | None |
| 7 | 07 | MUL | None |
| 8 | 08 | DIV | None |
| 9 | 09 | MOD | None |
| 10 | 0A | NEG | None |
| 11 | 0B | EQ | None |
| 12 | 0C | NE | None |
| 13 | 0D | LT | None |
| 14 | 0E | LE | None |
| 15 | 0F | GT | None |
| 16 | 10 | GE | None |
| 17 | 11 | AND | None |
| 18 | 12 | OR | None |
| 19 | 13 | NOT | None |
| 20 | 14 | PRINT | None |
| 21 | 15 | STRING | u8 length, then literal bytes |
| 22 | 16 | NL | None |
| 23 | 17 | JMP | u16 byte offset |
| 24 | 18 | JNZ | u16 byte offset |
| 25 | 19 | CALL | u16 byte offset |
| 26 | 1A | RET | None |
| 27 | 1B | FOR | u8 variable index |
| 28 | 1C | NEXT | u8 variable index |
| 29 | 1D | INPUT | u8 variable index |
| 30 | 1E | CLS | None |
| 31 | 1F | BEEP | None |
| 32 | 20 | WAIT | None |
| 33 | 21 | LOCATE | None |
| 34 | 22 | PSET | None |
| 35 | 23 | PRESET | None |
| 36 | 24 | DRAW | None |
| 37 | 25 | SOUND | None |
| 38 | 26 | TICKS | None |
| 39 | 27 | KEY | None |
| 40 | 28 | ABS | None |
| 41 | 29 | RND | None |
| 42 | 2A | OPENR | None |
| 43 | 2B | OPENW | None |
| 44 | 2C | GET | u8 variable index |
| 45 | 2D | PUT | None |
| 46 | 2E | CLOSE | None |
| 47 | 2F | EOF | None |
| 48 | 30 | HOUR | None |
| 49 | 31 | MINUTE | None |
| 50 | 32 | SECOND | None |
| 51 | 33 | PATH | u8 length, then pathname bytes |
Compatibility
MBX1 is a format for this VM. It is not ELF, PDP-11 a.out, a native instruction stream or a tokenized factory-BASIC cartridge. Header and bounds validation do not establish full semantic validity for manually edited bytecode. Use MBC from the matching release.