Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Instruction Set

Note

This page is currently a stub and needs more detail. How flags are set for each instruction are not documented yet.

Warning

This is not the final instruction set. While opcodes are very unlikely to change, new opcodes/instructions will be created as Starfrootle develops.

Opcodes are a single byte, so there can be at most 256 different instructions. Opcodes are grouped by their high nybble. Any byte that is not a defined opcode behaves like NoOp.

High nybbleGroup
0xSystem
1xLoads and stores
2xMoves, pushes and pops
3xArithmetic
4xLogic and shifts
5xBit operations (planned)
6xComparisons
7xJumps and branches
8xCalls and returns
9xBlock operations (planned)

Defined opcodes

OpcodeNameOperandsBytesFlagsEffect
00NoOpnone1nonedo nothing
01Haltnone1nonestop the CPU
10LoadConstD_ value3noneregister = value
11LoadMemD_ address5noneregister = byte at address
12StoreMemS_ address5nonebyte at address = register
13LoadIndirectDS2noneD = byte at address at S, S+1, S+2
14StoreIndirectDS2nonebyte at address at D, D+1, D+2 = S
20CopyDS2noneD = S
21SwapDS2noneexchange D and S
22PushS_2nonepush register onto the stack
23PopD_2nonepop the stack into register
30AddDS2Z C N VD = D + S
31SubDS2Z C N VD = D - S
32IncD_2Z N VD = D + 1
33DecD_2Z N VD = D - 1
40AndDS2Z ND = D & S
41OrDS2Z ND = D | S
42XorDS2Z ND = D ^ S
43NotD_2Z ND = ~D
44ShiftLeftDn2Z C ND <<= n
45ShiftRightDn2Z C ND >>= n
60CompareDS2Z C N Vcomputes D - S, only sets flags
70Jumpaddress4nonePC = address
71JumpIfZeroaddress4nonejump if Z set
72JumpIfNotZeroaddress4nonejump if Z clear
73JumpIfCarryaddress4nonejump if C set
74JumpIfNoCarryaddress4nonejump if C clear
75JumpIfNegativeaddress4nonejump if N set
76JumpIndirectaddress4nonePC = the 3-byte address stored at address
80Calladdress4nonepush return address (3 bytes), jump
81Returnnone1nonepop PC
82CallIndirectaddress4nonepush return address (3 bytes), jump to the address stored at address

Unused Operand Nybbles

For instances like D_ or S_, the low nybble _ is completley ignored.

Indirect Jump and Call

JumpIndirect and CallIndirect take the address of a vector instead of a destination. The CPU reads the 3-byte (big-endian) address stored at that location and jumps to it, so code can jump to an address that is stored in memory. For example, the boot ROM uses JumpIndirect on the reset vector in the ROM header to start a game.

Indirect Load and Store

Register indexes beyond 0xD will wrap around to the start of the register indexes. For instance 13 7F would set the register at index 0x7 with the value of the address defined by the registers 0xF 0x0 and 0x1.

Cycle Cost

For each instruction, it’s 1 cycle plus 1 per byte fetched or accessed. For instance, TODO PUT EXAMPLE