Fork me on GitHub

Specification info

link

Chip-8

download

Description:

A interpreted programming language for the COSMAC ELF.

CPU clock speed:

0

Address bus:

0-Bit

CPU caches:

Name Size Comment
L124 KBDivided into 16 KB for instructions and 8 KB for data.

Document version:

1.0.0

Sources:

Glossary

link

Glossary

Name Description
NNumber between 0 and 15
NNNumber between 0 and 255
NNNNumber between 0 and 4095
vxRegister from 0 - F
vyRegister from 0 - F
IMemory index register (Not directly accessible)
delayA 8-Bit register which counts down at 60 HZ until it reaches zero
buzzerA 8-Bit register which counts down at 60 HZ until it reaches zero. If the value is not zero a sound is playing
memMemory of the emulator.

Registers

link

Main-Processor

Name Value Size (Bits)
V00x008
V10x018
V20x028
V30x038
V40x048
V50x058
V60x068
V70x078
V80x088
V90x098
VA0x0A8
VB0x0B8
VC0x0C8
VD0x0D8
VE0x0E8
VF0x0F8

Load and Store Instructions

link

MOVC

Opcode:

6

Format:

MOVC vx, NN

Purpose:

Stores number NN in vx

Implementation:

vx = NN

How to decode:

opcode vx NN
4 4 8
link

MOVR

Opcode:

8

Format:

MOVR vx, vy

Purpose:

Stores the value of vy in vx

Implementation:

vx = vy

How to decode:

opcode vx vy 0
4 4 4 4

Atithmetic Instructions

link

ADDC

Opcode:

7

Format:

ADDC vx, NN

Purpose:

Adds the value NN to register vx

Implementation:

vx += NN

How to decode:

opcode vx NN
4 4 8
link

ADDR

Opcode:

8

Format:

ADDR vx, vy

Purpose:

Adds the value of register vy to register vx. Sets the VF to 01 if a carry (Integer overflow) occurs, otherwise to 00

Implementation:

vx += vy if int_overflow(): VF = 0x01 else: VF = 0x00

How to decode:

opcode vx vy 4
4 4 4 4
link

SUBR

Opcode:

8

Format:

SUBR vx, vy

Purpose:

Subtracts register vy from vx. VF is set to 01 if a borrow occurs (Integer underflow), otherwise to 00

Implementation:

vx -= vy if int_underflow(): VF = 0x01 else: VF = 0x00

How to decode:

opcode vx vy 5
4 4 4 4
link

SUBR2

Opcode:

8

Format:

SUBR2 vx, vy

Purpose:

Subtracts register vx from vy and stores the result in vx. VF is set to 01 if a borrow occurs (Integer underflow), otherwise to 00

Implementation:

vx = vy - vx if int_underflow(): VF = 0x01 else: VF = 0x00

How to decode:

opcode vx vy 7
4 4 4 4
link

ANDR

Opcode:

8

Format:

ANDR vx, vy

Purpose:

Sets vx to vx AND vy

Implementation:

vx = vx & vy

How to decode:

opcode vx vy 2
4 4 4 4
link

ORR

Opcode:

8

Format:

ORR vx, vy

Purpose:

Sets vx to vx OR vy

Implementation:

vx = vx | vy

How to decode:

opcode vx vy 1
4 4 4 4
link

XORR

Opcode:

8

Format:

XORR vx, vy

Purpose:

Sets vx to vx XOR vy

Implementation:

vx = vx ^ vy

How to decode:

opcode vx vy 3
4 4 4 4
link

SHRR

Opcode:

8

Format:

SHRR vx, vy

Purpose:

Stores the value of register vy shifted right by one bit in register vx. Sets VF to the old least significant bit

Implementation:

VF = vy & 0x1 vx = vy >> 1

How to decode:

opcode vx vy 6
4 4 4 4
link

SHLR

Opcode:

8

Format:

SHLR vx, vy

Purpose:

Stores the value of register vy shifted left by one bit in register vx. Sets VF to the old most significant bit

Implementation:

VF = vy & 0x80 vx = vy << 1

How to decode:

opcode vx vy E
4 4 4 4
link

RNDR

Opcode:

12

Format:

RNDR vx

Purpose:

Sets vx to a random number with a mask of NN

Implementation:

vx = randi() & NN

How to decode:

opcode vx NN
4 4 8

Jump and Branch Instructions

link

JMP

Opcode:

1

Format:

JMP NNN

Purpose:

Jumps to address NNN

Implementation:

I = NNN

How to decode:

opcode NNN
4 12
link

JMPREL

Opcode:

11

Format:

JMPREL NNN

Purpose:

Jumps to address NNN + V0

Implementation:

I = NNN + V0

How to decode:

opcode NNN
4 12
link

CALL

Opcode:

2

Format:

CALL NNN

Purpose:

Calls a subroutine at the address NNN.

Implementation:

stack.push(I) I = NNN

How to decode:

opcode NNN
4 12
link

RET

Opcode:

0

Format:

RET

Purpose:

Returns from a subroutine.

Implementation:

I = stack.pop()

How to decode:

opcode 0ee
4 12
link

CALLM

Opcode:

0

Format:

CALLM NNN

Purpose:

Calls a subroutine at the address NNN. This is an introduction to call a real machine code subroutine on the COSMAC ELF. The subroutine must be end with D4 to inform the chip-8 interpreter, that the routine is finished.

Implementation:

*(NNN)()

How to decode:

opcode NNN
4 12
link

JNEC

Opcode:

3

Format:

JNEC vx, NN

Purpose:

Skips the next introduction if vx == NN

Implementation:

if vx != NN:

How to decode:

opcode vx NN
4 4 8
link

JNER

Opcode:

5

Format:

JNER vx, vy

Purpose:

Skips the next introduction if vx == vy

Implementation:

if vx != vy:

How to decode:

opcode vx vy 0
4 4 4 4
link

JEC

Opcode:

4

Format:

JEC vx, NN

Purpose:

Skips the next introduction if vx != NN

Implementation:

if vx == NN:

How to decode:

opcode vx NN
4 4 8
link

JER

Opcode:

9

Format:

JER vx, vy

Purpose:

Skips the next introduction if vx != vy

Implementation:

if vx == vy:

How to decode:

opcode vx vy 0
4 4 4 4
link

KNE

Opcode:

14

Format:

KNE vx

Purpose:

Skips the following instruction, if the key corresponding to the hex value currently stored in register vx, is pressed

Implementation:

if key != vx:

How to decode:

opcode vx 9E
4 4 8
link

KE

Opcode:

14

Format:

KE vx

Purpose:

Skips the following instruction, if the key corresponding to the hex value currently stored in register vx, is not pressed

Implementation:

if key == vx:

How to decode:

opcode vx A1
4 4 8

Timers

link

DELAY

Opcode:

15

Format:

DELAY vx

Purpose:

Sets the delay timer to the value of register vx

Implementation:

delay = vx

How to decode:

opcode vx 15
4 4 8
link

DELAYR

Opcode:

15

Format:

DELAYR vx

Purpose:

Stores the current value of the delay timer in register vx

Implementation:

vx = delay

How to decode:

opcode vx 07
4 4 8
link

BUZZER

Opcode:

15

Format:

BUZZER vx

Purpose:

Sets the sound timer to the value of register vx

Implementation:

buzzer = vx

How to decode:

opcode vx 18
4 4 8

Keypad

link

WAITK

Opcode:

15

Format:

WAITK vx

Purpose:

Waits for a keypress and store the result in register VX

Implementation:

How to decode:

opcode vx 0A
4 4 8

Register I manipulation

link

SETI

Opcode:

10

Format:

SETI NNN

Purpose:

Stores memory address NNN in register I

Implementation:

I = NNN

How to decode:

opcode NNN
4 12
link

ADDI

Opcode:

15

Format:

ADDI vx

Purpose:

Adds the value stored in register vx to register I

Implementation:

I += vx

How to decode:

opcode vx 1E
4 4 8

Graphics

link

DRAW

Opcode:

13

Format:

DRAW vx, vy, N

Purpose:

Draws a sprite at position vx, vy with N bytes of sprite data starting at the address stored in I. Sets VF to 01 if any set pixels are changed to unset, and 00 otherwise

Implementation:

Draw(vx, vx)

How to decode:

opcode vx vy N
4 4 4 4
link

CLS

Opcode:

0

Format:

CLS

Purpose:

Clears the screen

Implementation:

Clear()

How to decode:

opcode 0E0
4 12
link

FNT

Opcode:

15

Format:

FNT vx

Purpose:

Sets I to the memory address of the sprite data corresponding to the hexadecimal digit stored in register vx

Implementation:

I = SearchLetter(vx)

How to decode:

opcode vx 29
4 4 8

BCD

link

BCD

Opcode:

15

Format:

BCD vx

Purpose:

Stores the binary-coded decimal equivalent of the value stored in register vx at addresses I, I+1, and I+2

Implementation:

mem[I] = vx / 100 % 10 mem[I + 1] = vx / 10 % 10 mem[I + 2] = vx % 10

How to decode:

opcode vx 33
4 4 8

Dump and load registers from memory

link

DMPR

Opcode:

15

Format:

DMPR vx

Purpose:

Stores the values of registers V0 to VX inclusive in memory starting at address I. I is set to I + X + 1 after the operation

Implementation:

for 0 to vx: mem[I++] = V[Idx]

How to decode:

opcode vx 55
4 4 8
link

RDR

Opcode:

15

Format:

RDR vx

Purpose:

Fill registers V0 to VX inclusive with the values stored in memory starting at address I. I is set to I + X + 1 after operation

Implementation:

for 0 to vx: V[Idx] = mem[I++]

How to decode:

opcode vx 65
4 4 8