creole/README.md

43 lines
1.6 KiB
Markdown
Raw Normal View History

2023-02-25 16:01:03 -05:00
Creole is a bytecode designed for microcontrollers. It's C source file
is less than 1000 lines long and does not depend on the C standard
library.
2023-02-05 06:44:37 -05:00
## Bytecode Format
2023-02-25 16:01:03 -05:00
The syntax of creole instructions are
[1 byte opcode][2 or more byte instruction]*[1 byte all zero]
Each creole instruction consists of pseudo-UTF-8 characters. The first
byte is an unsigned number between 0 and 127 (the high bit is clear). Each
2023-02-05 06:44:37 -05:00
suceeding pseudo-UTF-8 character is encoded as follows:
2023-02-06 23:50:50 -05:00
* `110HHHHx 10xxxxxx`
* `1110HHHH 10xxxxxx 10xxxxxx`
* `11110HHH 10Hxxxxx 10xxxxxx 10xxxxxx`
* `111110HH 10HHxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
* `1111110H 10HHHxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
* `11111110 10HHHHxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
2023-02-05 06:44:37 -05:00
2023-02-25 16:01:03 -05:00
The first four bits determine the type. The LSB high bit determines
if the encoded value is a register (`0001`) or immediate (`00X0`).
2023-02-12 15:45:51 -05:00
The second bit from LSB determines if the value should be treated
as a signed 32 bit two's compliment number (`001X`) or should be
2023-02-25 16:01:03 -05:00
treated as an unsigned 32 bit number (`000X`). All other values for
the high bits are reserved.
2023-02-05 06:44:37 -05:00
2023-02-25 16:01:03 -05:00
The rest of the bits encode a number that is up to 32 bits long.
Overlong encodings are accepted and sometimes used.
2023-02-07 11:38:04 -05:00
2023-02-12 15:45:51 -05:00
## Assembler
2023-02-25 16:01:03 -05:00
The macro assembler is Python (see the asm directory). The macro
assembler supports virtual instructions and jumps with named labels.
2023-02-12 15:45:51 -05:00
2023-02-07 11:38:04 -05:00
## Design Philsophy
Creole is small but not minimal. It is easy to add instructions, and
the amount of labels, registers, and stack space can changed at runtime.
System calls can be added dynamically, but static instructions that take
at most 3 arguments should be hard-coded.