Cricket Bytecode Generation

Cricket Bytecode

The following table lists Cricket bytecode. Each bytecode is listed with its opcode, mnemonic, whether it will create value on the Cricket VM stack, and the number of operands it will take, and a description of the operation.

Function Call Bytecode (or The Lack Of)

Cricket does not have dedicated function call bytecode, the generated bytecode sequence for function call is:

take the 16-bit function address, bit OR the address with 0x8000, and the result is two bytes for function call.
For examle, the main function memory address is at: 0x00, call main will be:
0x0000 | 0x8000 (expand to 16bit)-> 0x80 0x00, or -128, 0.
In general, if the highest bit of a bytecode is set, it indicates a function call, and use the above rule to determine the function address.

 

Chirp Binary File Format

Chirp has a simple binary format and is defined as following:

Byte offset Description
0x00-0x03 Magic number "CHRP", or 0x43485250
0x04-0x05 ROM address of code segment, unsigned 16-bit number in big-endian format: (0x04)<<8+(0x05)
0x06-0x07 ROM address of main function, unsigned 16-bit number in big-endian format
0x08-0x09 length of code segment, should satisfy invariant: code_length +10 = file_length
0x0a to end Chirp bytecode, length specified by the length field

 

Acknowledgements