Casio_asm/doc/bin_file.md

34 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2018-06-29 10:54:22 +02:00
# Bytecode
These files are [instructions][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][interpreter].
## The header
The header contains a magic number, which is hex `12345678`, a version number, an optional hash of the associated [assembler file][asm_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
[instructions]: ./instructions.md
[interpreter]: ./interpreter.md
[asm_file]: ./asm_file.md