187. Rts implied
wire implied RTS opcode $60.
Lesson 187 of 356 · tests/chapter_01_cpu/test_187_RTS_implied.py
Prerequisite: step 186 supplied `rts. In this step, add its import and direct table mapping in emulator/cpu/opcodes.py`:
from emulator.cpu.instructions import rts
OPCODE_TABLE = {
# existing entries...
0x60: rts,
}Opcode
0x60 -> RTSGoal
add opcode 0x60 to OPCODE_TABLE.
Student guidance
RTS uses implied addressing. That means the opcode has no operand bytes. The instruction gets all information it needs from the CPU stack.
Example
60 -> RTSExecution steps
1. CPU.step() fetches opcode 0x60.
2. OPCODE_TABLE dispatches directly to rts(cpu).
3. RTS pulls the return address from the stack.
4. RTS sets PC to pulled_address + 1.Common mistake
Do not fetch an operand byte for RTS. It is an implied instruction.
Why this step exists
`CPU.step has already consumed the sole opcode byte, and rts` gets its return word from the stack, so no wrapper or addressing mode is needed. Invariants: $60 maps directly to the one-argument function; dispatch does not consume $8001; RTS alone performs the two pulls and PC update. Misconception: every opcode does not require a named handler.
Out of scope: flag helpers and BRK are steps 188-190; RTI and opcode $40 are steps 191-192.
Run this lesson
uv run pytest tests/chapter_01_cpu/test_187_RTS_implied.py -v