Skip to content
Fetch-Decode-Execute
step 1/5

Reading — step 1 of 5

Read

~2 min readCHIP-8 Architecture

Fetch-Decode-Execute

Each instruction is 2 bytes, big-endian. Fetch:

python

Decode patterns by hex digits. CHIP-8 instructions are usually written as 4 hex digits:

PatternMnemonicEffect
00E0CLSClear display
00EERETReturn from subroutine
1NNNJP NNNJump to NNN
2NNNCALL NNNCall subroutine at NNN
3XKKSE VX, KKSkip next if VX == KK
4XKKSNE VX, KKSkip next if VX != KK
5XY0SE VX, VYSkip if VX == VY
6XKKLD VX, KKVX = KK
7XKKADD VX, KKVX += KK
8XY0..7,ELD/AND/OR/etcALU ops on VX, VY
9XY0SNE VX, VYSkip if VX != VY
ANNNLD I, NNNI = NNN
BNNNJP V0, NNNJump to V0 + NNN
CXKKRND VX, KKVX = random & KK
DXYNDRW VX, VY, NDraw N-byte sprite at (VX, VY)
EX9ESKP VXSkip if key VX pressed
EXA1SKNP VXSkip if key VX not pressed
FX07LD VX, DTVX = delay timer
FX0ALD VX, KWait for key, store in VX
FX15LD DT, VXDelay timer = VX
FX18LD ST, VXSound timer = VX
FX1EADD I, VXI += VX
FX29LD F, VXI = address of digit VX in font set
FX33LD B, VXBCD of VX into memory[I, I+1, I+2]
FX55LD [I], VXStore V0..VX into memory[I..]
FX65LD VX, [I]Load V0..VX from memory[I..]

Decoder:

python

Dispatch:

python

Most opcodes are simple; DRW (sprite drawing) is the complex one.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…