Reading — step 1 of 5
Read
~2 min readInstructions
ALU & Skip Instructions
The 8XYn family does ALU ops between VX and VY:
| n | Op | Effect |
|---|---|---|
| 0 | LD | VX = VY |
| 1 | OR | VX = VX OR VY |
| 2 | AND | VX = VX AND VY |
| 3 | XOR | VX = VX XOR VY |
| 4 | ADD | VX += VY, VF = carry |
| 5 | SUB | VX -= VY, VF = NOT borrow (1 if VX > VY) |
| 6 | SHR | VX = VX >> 1, VF = LSB before shift |
| 7 | SUBN | VX = VY - VX, VF = NOT borrow |
| E | SHL | VX = 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 ifVX == KK.4XKK: skip ifVX != KK.5XY0: skip ifVX == VY.9XY0: skip ifVX != VY.EX9E: skip if keyVXis pressed.EXA1: skip if keyVXis 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…