DCPU-16 Specification

Instruction Set

Instructions are 1-3 words long and are fully defined by the first word. In a basic instruction, the lower five bits of the first word of the instruction are the opcode, and the remaining eleven bits are split into a five bit value b and a six bit value a. b is always handled by the processor after a, and is the lower five bits. In bits (in LSB-0 format), a basic instruction has the format: aaaaaabbbbbooooo

In the tables below, C is the time required in cycles to look up the value, or perform the opcode, VALUE is the numerical value,NAME is the mnemonic, and DESCRIPTION is a short text that describes the opcode or value.

Values: (5/6 bits)

C VALUE DESCRIPTION
0 0x00-0x07 register (A, B, C, X, Y, Z, I or J, in that order)
0 0x08-0x0f [register]
1 0x10-0x17 [register + next word]
0 0x18 (PUSH / [--SP]) if in b, or (POP / [SP++]) if in a
0 0x19 [SP] / PEEK
1 0x1a [SP + next word] / PICK n
0 0x1b SP
0 0x1c PC
0 0x1d EX
1 0x1e [next word]
1 0x1f next word (literal)
0 0x20-0x3f literal value 0xffff-0x1e (-1..30) (literal) (only for a)
  • "next word" means "[PC++]". Increases the word length of the instruction by 1.
  • By using 0x18, 0x19, 0x1a as PEEK, POP/PUSH, and PICK there's a reverse stack starting at memory location 0xffff. Example: "SET PUSH, 10", "SET X, POP"
  • Attempting to write to a literal value fails silently