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.
| Opcode | Mnemonic | Create Stack value? | Number of operands | Description |
0 |
code-end | no | 0 | terminates code |
1 |
byte | yes | followed by 1 byte | convert follow up byte immediate value to 16-bit unsigned number and pushed onto stack (value 0-255). |
2 |
number | yes | followed by 2 bytes | convert follow up 2 bytes immediate value to 16-bit number and pushed onto stack |
3 |
list | no | 0 | "start of list"; opens a code block, followed by number of bytes of list (excluding list opcode and the list length byte, but including eol) |
4 |
eol | no | 0 | "end of list"; closes a code block |
5 |
eolr | yes | 0 | "end of list reporter"; closes a code block that will create a stack value |
6 |
lthing | yes | 1 | "local thing"; push to stack the function arguments, followed by index of call arguments in reverse order: 0 is arg_n (last argument), 1 is arg_n-1, etc. Example: for foo(a, b, c, d), d will be refered as lthing 0, c as lthing 1, b as lthing 2, a as lthing 3. |
7 |
stop | no | 0 | void return from callee function to caller |
8 |
output | no | 1 | return value from callee to caller |
9 |
repeat | no | 2 | repeats code block for specific number of times, first operand is loop count, second operand is loop body, represented as a list. |
10 |
if | no | 2 | if input expression is true, executes true branch, first operand is test conditional expression, second operand is true branch code block |
11 |
ifelse | no | 3 | if input expression is true, executes true branch, else executes false branch, first operand is test conditional, second operand is true branch code block, third operand is false branch code block |
12 |
beep | no | 0 | causes Cricket to beep |
13 |
note | no | 2 | makes Cricket play note of specified pitch and duration, first operand is pitch, second operand is duration |
14 |
waituntil | no | 1 | repeatedly executes body block until condition block evaluates to true, first operand is condition expression, second operand is body code block |
15 |
loop | no | 1 | unconditional loop to executes body block, operand is body block |
16 |
wait | no | 1 | waits for specified time period, operand is time is 1/10 second |
17 |
timer | yes | 0 | push to stack value of system timer |
18 |
resett | no | 0 | resets system timer to zero |
19 |
send | no | 1 | sends specified value out IR port, with 0.1 sec trailing delay, operand is the send value |
20 |
ir | yes | 0 | push to stack the value of most recently received IR byte |
21 |
newir? | yes | 0 | push to stack whether IR value has been received since last call to "ir" |
22 |
random | yes | 0 | push to stack pseudorandom 16 bit value |
23 |
+ | yes | 2 | push to stack sum of two inputs |
24 |
- | yes | 2 | push to stack difference of two imputs |
25 |
* | yes | 2 | push to stack product of two inputs |
26 |
/ | yes | 2 | push to stack division of two inputs |
27 |
% | yes | 2 | push to stack remainder of division of two inputs |
28 |
= | yes | 2 | push to stack boolean equality of two inputs |
29 |
> | yes | 2 | push to stack boolean "greater than" of two inputs |
30 |
< | yes | 2 | push to stack boolean "less than" of two inputs |
31 |
and | yes | 2 | push to stack bitwise AND of two inputs |
32 |
or | yes | 2 | push to stack bitwise OR of two inputs |
33 |
xor | yes | 2 | push to stack bitwise XOR of two inputs |
34 |
not | yes | 1 | push to stack (0x0001 and (input XOR 0x0001)). In other words, does a NOT on the low bit and push to stack just that low bit. If you need bitwise not, XOR with 0xffff. |
35 |
setglobal | no | 2 | sets numbered global to value |
36 |
global | yes | 1 | push to stack value of numbered global |
37 |
aset | no | 3 | sets numbered array with numbered element to value |
38 |
aget | yes | 2 | push to stack value of numbered element of numbered array |
39 |
record | no | 1 | records 8-bit value into data buffer |
40 |
recall | yes | 0 | push to stack 8-bit value stored in data buffer |
41 |
resetdp | no | 0 | resets data buffer pointer to zero |
42 |
setdp | no | 1 | sets data buffer pointer to specified value |
43 |
erase | no | 1 | erases data point |
44 |
when | no | 2 | sets up daemon with condition block and action block |
45 |
whenoff | no | 0 | terminates "when" daemon |
46 |
a, | no | 0 | selects motor A for control |
47 |
b, | no | 0 | selects motor B for control |
48 |
ab, | no | 0 | selects motors A and B |
49 |
on | no | 0 | turns on selected motor(s) |
50 |
onfor | no | 1 | turns on selected motor(s) for specified period of time |
51 |
off | no | 0 | turns off selectec motor(s) |
52 |
thisway | no | 0 | sets selected motor(s) direction to green LED |
53 |
thatway | no | 0 | sets selected motor(s) direction to red LED |
54 |
rd | no | 0 | reverses direction of selected motor(s) |
55 |
sensora | yes | 0 | push to stack value of sensor A |
56 |
sensorb | yes | 0 | push to stack value of sensor B |
57 |
switcha | yes | 0 | push to stack boolean value of sensor A |
58 |
switchb | yes | 0 | push to stack boolean value of sensor B |
59 |
setpower | no | 1 | sets power level of selected motor(s), first operand is the value |
60 |
brake | no | 0 | sets selected motor(s) for active braking |
61 |
bsend | no | 1 | sends value out Bus Port |
62 |
bsr | yes | 1 | sends value out Bus Port and push reply value to stack, operand is the value |
63 |
c, | no | 0 | selects bus motor C for control |
64 |
d, | no | 0 | selects bus motor D for control |
65 |
cd, | no | 0 | selects bus motors C and D for control |
66 |
abcd, | no | 0 | selects all motors for control |
67 |
fastsend | no | 1 | sends specified value out IR port without trailing delay, first operand is the value |
68 |
stop! | no | 0 | terminates execution completely, system exit |
69 |
eb | yes | 1 | "examine byte"; push to stack the value of Cricket memory at specified address, operand is the address |
70 |
db | no | 2 | "deposit byte"; store byte into Cricket memory, first operand is address, second operand is value |
71 |
low-byte | yes | 1 | push to stack low byte of operand |
72 |
high-byte | yes | 1 | push to stack high byte of operand |
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 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 |