DCPU-16, short for DCPU-16 Virtual CPU Architecture, was created by Markus Persson in 2012 for the game 0x10c. DCPU-16 is a fictional 16-bit CPU instruction set and assembly language used primarily for educational purposes, hobbyist programming, and emulation projects. Developers can access DCPU-16 emulators through DCPU-16 Emulator, which provides instruction references, example code, and emulator downloads for Windows, macOS, and Linux.

DCPU-16 exists to simulate a simple CPU architecture that is easy to understand and program while demonstrating fundamental assembly and hardware concepts. Its design philosophy emphasizes minimalism, readability, and hands-on experimentation. By providing a small, self-contained instruction set, DCPU-16 solves the problem of teaching low-level programming, CPU operations, and hardware interaction in an approachable way.

DCPU-16: Registers and Memory

DCPU-16 provides eight general-purpose registers (A, B, C, X, Y, Z, I, J) and a 16-bit memory address space.

SET A, 0x30     ; Set register A to 0x30
SET [0x1000], 0x20  ; Store 0x20 in memory address 0x1000
ADD A, [0x1000]   ; Add value from memory to A

Registers store temporary values while memory holds persistent data. This layout allows low-level control similar to assembly programming in Assembly and emulated CPUs like 6502.

DCPU-16: Instructions and Operations

DCPU-16 supports basic arithmetic, logic, branching, and memory instructions.

SET B, 0x10
SUB A, B       ; Subtract B from A
IFN A, 0x0
    SET PC, 0x200  ; Jump if A is not zero
ENDIF

Instructions enable control flow, data manipulation, and conditional branching. This simple instruction set makes experimentation straightforward, comparable to Assembly and 6502 programming.

DCPU-16: Stack and Subroutines

DCPU-16 provides a stack for temporary storage and supports subroutine calls and returns.

PUSH A        ; Push value of A onto the stack
SET A, 0x0
POP B         ; Pop value into B
JSR 0x300     ; Jump to subroutine at 0x300

Stack operations enable modular code and function-like behavior. This mechanism is conceptually similar to call stacks in real-world CPUs and Assembly.

DCPU-16: Input/Output and Hardware

DCPU-16 supports simple hardware interaction through memory-mapped I/O, allowing emulated devices to be controlled.

SET [0x8000], 0x01  ; Turn on a device mapped at 0x8000
GET C, [0x8000]       ; Read device state into C

Memory-mapped I/O allows programs to interact with virtual hardware, demonstrating principles similar to real CPU I/O systems.

DCPU-16 is used in hobbyist programming, educational exercises, and retro game development projects. Its simplicity and clarity make it an excellent introduction to CPU architecture, assembly programming, and low-level hardware concepts alongside real-world languages and architectures like Assembly, 6502, and C++.