Skip to content
ALU & Skip Instructions
step 1/5

Reading — step 1 of 5

Read

~2 min readInstructions

ALU & Skip Instructions

The 8XYn family does ALU ops between VX and VY:

nOpEffect
0LDVX = VY
1ORVX = VX OR VY
2ANDVX = VX AND VY
3XORVX = VX XOR VY
4ADDVX += VY, VF = carry
5SUBVX -= VY, VF = NOT borrow (1 if VX > VY)
6SHRVX = VX >> 1, VF = LSB before shift
7SUBNVX = VY - VX, VF = NOT borrow
ESHLVX = VX << 1, VF = MSB before shift

Note quirk: in original CHIP-8, SHR/SHL set VX = VY << 1 or VY >> 1 (uses VY!). Modern interpreters often shift VX directly, ignoring VY. Different ROMs assume different behavior; emulators have a "quirk mode" toggle.

python

Skip instructions: skip the next instruction (advance pc by 4 instead of 2):

  • 3XKK: skip if VX == KK.
  • 4XKK: skip if VX != KK.
  • 5XY0: skip if VX == VY.
  • 9XY0: skip if VX != VY.
  • EX9E: skip if key VX is pressed.
  • EXA1: skip if key VX is not pressed.

These let games conditionally branch.

python

Discussion

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

Sign in to post a comment or reply.

Loading…