CHIP-8 Emulator and Assembler

by Matthew Obi ©2021-2023


Assembly Reference

All instructions are written in 'operation operand1, operand2...' style. All instructions assemble to 2-bytes unless otherwise stated.

Operand Value
nnnn A 16-bit unsigned integer constant.
nnn A 12-bit unsigned integer constant.
nn An 8-bit unsigned integer constant.
vx, vy A register with index between 0 and f. (v0, va)
h A 4-bit unsigned integer constant.
@label A label value.

word nnnn -> (0xnnnn)

Assembles to a 16-bit unsigned constant integer at the located address. Takes up 2 bytes.

byte nn -> (0xnn)

Assembles to an 8-bit unsigned constant integer at the located address. Takes up 1 byte.

jp @label OR jp nnn -> (0x1nnn)

Changes the program counter to the location value of 'label' or a 12-bit constant address.

call @label OR call nnn -> (0x2nnn)

Same as 'jp', but saves execution location so that it can be returned to with 'ret'

ret -> (0x00EE)

Returns to last execution location saved with 'call'.

cls -> (0x00E0)

Clears the screen.

ld vx, nn -> (0x6xnn)

Loads a constant 8-bit unsigned value into register 'vx'.

ld vx, vy -> (0x8xy0)

Copies the value of register 'vy' into register 'vx'.

add vx, nn -> (0x7xnn)

Adds a constant 8-bit unsigned value to register 'vx'.

add vx, vy -> (0x8xy4)

Adds the value of register 'vy' to register 'vx'. Register 'vf' is set to 1 if the addition results in an overflow. Otherwise, 'vf' is set to 0.

sub vx, vy -> (0x8xy5)

Subtracts the value of register 'vy' from register 'vx' and stores the result in register 'vx'. Register 'vf' is set to 0 if a borrow is required. Otherwise, 'vf' is set to 1.

subn vx, vy -> (0x8xy7)

Subtracts the value of register 'vx' from register 'vy' and stores the result in register 'vx'. Register 'vf' is set to 0 if a borrow is required. Otherwise, 'vf' is set to 1.

or vx, vy -> (0x8xy1)

Performs the binary or operation on register 'vx' and register 'vy' and stores the result in register 'vx'.

and vx, vy -> (0x8xy2)

Performs the binary and operation on register 'vx' and register 'vy' and stores the result in register 'vx'.

xor vx, vy -> (0x8xy3)

Performs the binary xor operation on register 'vx' and register 'vy' and stores the result in register 'vx'.

shl vx -> (0x8x06)

Sets the value of register 'vf' to the most significant bit of register 'vx', then multiplies 'vx' by 2.

shr vx -> (0x8x0E)

Sets the value of register 'vf' to the least significant bit of register 'vx', then divides 'vx' by 2.

se vx, nn -> (0x3xnn)

Skips the next instruction if register 'vx' is equal to a constant 8-bit unsigned value.

se vx, vy -> (0x5xy0)

Skips the next instruction if register 'vx' is equal to register 'vy'.

sne vx, nn -> (0x4xnn)

Skips the next instruction if register 'vx' is not equal to a constant 8-bit unsigned value.

sne vx, vy -> (0x9xy0)

Skips the next instruction if register 'vx' is not equal to register 'vy'.

rnd vx, nn -> (0xCxnn)

Sets register 'vx' to a random number that is the binary and of a random integer and a constant 8-bit unsigned value. (rand() & nn)

ld i, @label OR ld i, nnn -> (0xAnnn)

Loads into address register 'i' the address of 'label' or a 12-bit constant address.

add i, vx -> (0xFx1E)

Adds the value of register 'vx' to the address register 'i'.

drw vx, vy, h -> (0xDxyh)

Draws an 8xh sprite, with data starting at 'i', at location 'vx', 'vy' on the screen. If a pixel is drawn over an existing pixel, the pixel is turned off and register 'vf' is set to 1.

skp vx -> (0xEx9E)

Skips the next instruction if the key whose index is stored in register 'vx' is pressed.

sknp vx -> (0xExA1)

Skips the next instruction if the key whose index is stored in register 'vx' is not pressed.

ld dt, vx -> (0xFx15)

Loads into the delay timer the value of register 'vx'.

ld st, vx -> (0xFx18)

Loads into the sound timer the value of register 'vx'.

ld vx, dt -> (0xFx07)

Loads into register 'vx', the value of the delay timer.

ld vx, k -> (0xFx0A)

Pauses execution until a key is pressed, then sets register 'vx' to the index of the key pressed.

ld f, vx -> (0xFx29)

Loads into the register 'i' the location of the sprite representing the value of register 'vx'.

ld b, vx -> (0xFx33)

Writes the BCD representation of the value of register 'vx' to memory starting at the address stored in register 'i'.

ld [i], vx -> (0xFx55)

Copies the values of registers 'v0' through 'vx' to memory starting at the address stored in 'i'.

ld vx, [i] -> (0xFx65)

Reads the values of registers 'v0' through 'vx' from memory starting at the address stored in 'i'.