Skip to content

CHIP 8 Reference Manual

Theodor-Lindberg edited this page Feb 4, 2019 · 7 revisions

This is my implementation that I came up with after analyzing many different sources scattered across the internet but it's mainly based on this collected work. Note that all binary numbers uses the little endian convention.

Table of contents

  1. Memory mapping
    1.1 Font set
    1.2 Registers
  2. Timers
  3. Keyboard input
  4. Instruction set

1 Memory mapping

The CHIP-8 has 4096 bytes of memory, where 0x000-0x1FF which is usually reserved for the interpreter is used for the font set and the data/program is stored in 0x200-0xFFF.

1.1 Font set

The CHIP-8 comes with a default font set representing the hexadecimal digits 0 - F:

0xF0, 0x90, 0x90, 0x90, 0xF0,	// 0
0x20, 0x60, 0x20, 0x20, 0x70,	// 1
0xF0, 0x10, 0xF0, 0x80, 0xF0,	// 2
0xF0, 0x10, 0xF0, 0x10, 0xF0,	// 3
0x90, 0x90, 0xF0, 0x10, 0x10,	// 4
0xF0, 0x80, 0xF0, 0x10, 0xF0,	// 5
0xF0, 0x80, 0xF0, 0x90, 0xF0,	// 6
0xF0, 0x10, 0x20, 0x40, 0x40,	// 7
0xF0, 0x90, 0xF0, 0x90, 0xF0,	// 8
0xF0, 0x90, 0xF0, 0x10, 0xF0,	// 9
0xF0, 0x90, 0xF0, 0x90, 0x90,	// A
0xE0, 0x90, 0xE0, 0x90, 0xE0,	// B
0xF0, 0x80, 0x80, 0x80, 0xF0,	// C
0xE0, 0x90, 0x90, 0x90, 0xE0,	// D
0xF0, 0x80, 0xF0, 0x80, 0xF0,	// E
0xF0, 0x80, 0xF0, 0x80, 0x80	// F

For example:
The character 'E' is stored in memory as 0xF0, 0x80, 0xF0, 0x80, 0xF0, the bits can then can be rendered as such:

Hex  | Binary    | Pixels
0xF0 | 1111 0000 | ****  
‭0x80 | 1000 0000 | *  ‬
0xF0 | 1111 0000 | ****  
‭0x80 | 1000 0000‬ | *
0xF0 | 1111 0000 | ****

1.2 Registers

  • 16 8-bit general purpose registers, but the last register is used as flag for many instructions (e.g a carry flag). Often referred to as V0-VF.
  • 16-bit index registry called 'I' which is used to store a temporary addresses.
  • 8-bit program counter that contains the current executing address.
  • 8-bit stack pointer that points to the current stack frame.
  • 16 frames of stack where each stack frame is 16-bit, it used to store addresses before jumping into subroutines.
  • 8-bit register to store the value of the delay timer.
  • 8-bit register to store the value of the sound timer.

3 Timers

4 Keyboard input

The CHIP-8 originally had a 16-key hexadecimal keypad with the following layout:

1   2   3   C
4   5   6   D
7   8   9   E
A   0   B   F

But since that is very much obselete I've mappped the keys to a modern keyboard with this layout:

1   2   3   4
Q  W  E   R
A   S   D  F
Z   X   C  V

5 Instruction set

The following is a reference table containing all implemented CHIP-8 instructions. NNN refers to a hexadecimal memory address, NN refers to a hexadecimal byte, N refers to a hexadecimal nibble, and X and Y refer to registers.