Specification info
Description:
A interpreted programming language for the COSMAC ELF.
CPU clock speed:
0
Address bus:
0-Bit
CPU caches:
Name | Size | Comment |
---|---|---|
L1 | 24 KB | Divided into 16 KB for instructions and 8 KB for data. |
Document version:
1.0.0
Sources:
Glossary
Glossary
Name | Description |
---|---|
N | Number between 0 and 15 |
NN | Number between 0 and 255 |
NNN | Number between 0 and 4095 |
vx | Register from 0 - F |
vy | Register from 0 - F |
I | Memory index register (Not directly accessible) |
delay | A 8-Bit register which counts down at 60 HZ until it reaches zero |
buzzer | A 8-Bit register which counts down at 60 HZ until it reaches zero. If the value is not zero a sound is playing |
mem | Memory of the emulator. |
Registers
Main-Processor
Name | Value | Size (Bits) |
---|---|---|
V0 | 0x00 | 8 |
V1 | 0x01 | 8 |
V2 | 0x02 | 8 |
V3 | 0x03 | 8 |
V4 | 0x04 | 8 |
V5 | 0x05 | 8 |
V6 | 0x06 | 8 |
V7 | 0x07 | 8 |
V8 | 0x08 | 8 |
V9 | 0x09 | 8 |
VA | 0x0A | 8 |
VB | 0x0B | 8 |
VC | 0x0C | 8 |
VD | 0x0D | 8 |
VE | 0x0E | 8 |
VF | 0x0F | 8 |
Load and Store Instructions
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 |
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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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
JMP
Opcode:
1
Format:
JMP NNN
Purpose:
Jumps to address NNN
Implementation:
I = NNN
How to decode:
opcode | NNN |
---|---|
4 | 12 |
JMPREL
Opcode:
11
Format:
JMPREL NNN
Purpose:
Jumps to address NNN + V0
Implementation:
I = NNN + V0
How to decode:
opcode | NNN |
---|---|
4 | 12 |
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 |
RET
Opcode:
0
Format:
RET
Purpose:
Returns from a subroutine.
Implementation:
I = stack.pop()
How to decode:
opcode | 0ee |
---|---|
4 | 12 |
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 |
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 |
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 |
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 |
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 |
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 |
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
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 |
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 |
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
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
SETI
Opcode:
10
Format:
SETI NNN
Purpose:
Stores memory address NNN in register I
Implementation:
I = NNN
How to decode:
opcode | NNN |
---|---|
4 | 12 |
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
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 |
CLS
Opcode:
0
Format:
CLS
Purpose:
Clears the screen
Implementation:
Clear()
How to decode:
opcode | 0E0 |
---|---|
4 | 12 |
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
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
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 |
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 |