I am building a W65C02S based computer for fun, and I try to build basically all the tools myself. Including the assembler (yes, I know they exist, I just want to make everything from scratch myself, for fun).
When working on the JSR
opcode (absolute addressing mode), I find that before it puts the program counter on the stack, it reads one byte off the stack first (program counter is set to 80 2e
at this point, the stack pointer is 01b6
):
READ address: 80 2e data: 20 JSR ; Read the opcode
READ address: 80 2f data: 14 14 ; Read the LO byte of operand
READ address: 01 b6 data: 74 't' ; Read the stack (why?!)
WRITE address: 01 b6 data: 80 --- ; Write HI byte of PC
WRITE address: 01 b5 data: 30 '0' ; Write LO byte of PC
READ address: 80 30 data: 80 80 ; Read HI byte of operand
READ address: 80 14 data: 8d STA ; Read opcode at `80 14` (the JSR operand)
It works OK, but what it the reason it reads from the stack first?
(To explain the table: this is from my own tool. I am using an Arduino to look at the data and address buses to see what is happening there. It is a hardware CPU running only my own code.)