This document provides an overview of the CHIP-8 assembly mnemonics supported by the emulator's built-in editor. Each mnemonic represents a specific instruction that can be executed by the CHIP-8 interpreter.
This was largely based on Cowgod's excellent technical reference, so it's worth also reading through that.
The instructions below are formated as (Instruction
- Bytecode
)
The bytecodes hint to the arguments accepted for this instruction, where numbers or upper case letters are constant, but lower case letters indicate the types it deals with, which are listed below:
nnn
oraddr
- A 12-bit value, the lowest 12 bits of the instructionn
ornibble
- A 4-bit value, the lowest 4 bits of the instructionx
- A 4-bit value, the lower 4 bits of the high byte of the instructiony
- A 4-bit value, the upper 4 bits of the low byte of the instructionkk
orbyte
- An 8-bit value, the lowest 8 bits of the instruction
Asside from the instructions (below this section), there's other bits of syntax available to make life easier.
You can "define" values at the top of your file (Before any instructions). These behave like constants:
DEFINE <TYPE> <NAME> <VALUE>
TYPE
- One ofREGISTER, ADDRESS, BYTE, NIBBLE
.NAME
- The name to refer to laterVALUE
- The value (Must match the type)
You can "label" a section as <label_name>:
.
For example, you can use this to refer to some data:
smile:
0b00100100
0b00100100
0b00000000
0b10011001
0b01000010
0b00111100
...
LD I, smile
Or you could use this to refer to a subprocess for a CALL
or to JP
JP mainLoop
draw:
CLS
DRW X_COORD, Y_COORD, 6 ; Some "DEFINED" values here
RET
mainLoop:
CALL draw
JP mainLoop
moveVertical: SE IS_MOVING_DOWN, 0 JP moveDown JP moveUp
Anything after a ;
is a comment.
Clear the Display.
- Clears the screen, setting all pixels to 0.
Return from Subroutine.
- Returns execution to the address stored on the stack by the last
CALL
instruction.
Jump to Address.
JP nnn
: Jumps to the addressnnn
.JP V0, addr
: Jumps to the addressnnn + V0
.
Call Subroutine.
- Calls the subroutine at address
nnn
, storing the return address on the stack.
Skip Next Instruction if Equal.
SE Vx, kk
: Skips the next instruction if the value in registerVx
equalskk
.SE Vx, Vy
: Skips the next instruction if the value in registerVx
equals the value in registerVy
.
Skip Next Instruction if Not Equal.
SNE Vx, kk
: Skips the next instruction if the value in registerVx
does not equalkk
.SNE Vx, Vy
: Skips the next instruction if the value in registerVx
does not equal the value in registerVy
.
Load Value.
LD Vx, kk
: Loads the valuekk
into registerVx
.LD Vx, Vy
: Loads the value in registerVy
into registerVx
.LD I, addr
: Loads the addressnnn
into the index registerI
.LD Vx, [I]
: Loads values from memory starting at addressI
into registersV0
toVx
.LD [I], Vx
: Stores values from registersV0
toVx
into memory starting at addressI
.LD Vx, DT
: Loads the delay timer value into registerVx
.LD DT, Vx
: Sets the delay timer to the value in registerVx
.LD ST, Vx
: Sets the sound timer to the value in registerVx
.LD F, Vx
: Loads the address of the sprite for the hexadecimal digit stored inVx
intoI
.LD B, Vx
: Stores the binary-coded decimal representation ofVx
in memory at addressesI
,I+1
, andI+2
.LD Vx, K
: Waits for a key press and stores the result inVx
.
Add Values.
ADD Vx, kk
: Adds the valuekk
toVx
, storing the result inVx
.ADD Vx, Vy
: Adds the value in registerVy
toVx
, storing the result inVx
.ADD I, Vx
: Adds the value in registerVx
to the index registerI
.
Bitwise OR.
- Performs a bitwise OR between registers
Vx
andVy
, storing the result inVx
.
Bitwise AND.
- Performs a bitwise AND between registers
Vx
andVy
, storing the result inVx
.
Bitwise XOR.
- Performs a bitwise XOR between registers
Vx
andVy
, storing the result inVx
.
Subtract Values.
- Subtracts the value in register
Vy
fromVx
, storing the result inVx
. Sets the carry flag to1
ifVx > Vy
.
Shift Right.
- Shifts the value in register
Vx
right by one bit. The least significant bit is stored in the carry flag.
Subtract Values (Reverse).
- Subtracts the value in register
Vx
fromVy
, storing the result inVx
. Sets the carry flag to1
ifVy > Vx
.
Shift Left.
- Shifts the value in register
Vx
left by one bit. The most significant bit is stored in the carry flag.
Random Number AND.
- Sets
Vx
to a random number ANDed withkk
.
Draw Sprite.
- Draws an
n
-byte sprite at coordinates(Vx, Vy)
starting from memory locationI
. The sprite is XORed onto the display, and the collision flagVF
is set if any pixels are erased.
Skip Next Instruction if Key Pressed.
- Skips the next instruction if the key corresponding to the value in
Vx
is pressed.
Skip Next Instruction if Key Not Pressed.
- Skips the next instruction if the key corresponding to the value in
Vx
is not pressed.