Casio_asm/doc/bin_file.md

1.6 KiB

Bytecode

These files are instructions in their binary form along with their arguments. These files also contain a header.
These files are meant to be executed by the interpreter.

The header

The header contains a magic number, which is hex 12345678, a version number, an optional hash of the associated assembler file, the entry point of the program and the MMU mappings required by the program.

Binary instructions

Instructions fall in two categories: normal and extended.
Instructions are variable-length instructions, and their size is anywhere between one and four bytes.

First byte

The first byte denotes the instruction type.

The most significant two bits represent the argument scheme:
00: No arguments, the instruction ends there
01: One argument from a register
10: Two arguments from registers
11: An immediate argument

The least significant six bits of the first byte represent the opcode. If it is bin 111111 then the instruction is extended and its opcode is stored in the second byte.

The arguments

In the case of one or two arguments from registers, the opcode is followed by one or two bytes containing the number of the register from hex 00 to hex ff.

In the case of an immediate argument, it is encoded as either a big-endian 16-bit integral number or a decimal value in the following format:
MSB: sign of the number, 1 means negative
Subsequent 11 bits: mantissa
Remaining 4 bits: exponent, the power of two the mantissa is taken to