Dead cycles
Posted: Fri May 08, 2009 7:17 pm
Each 6502 instruction takes so many cycles as number of R/W operations plus sometimes some dead cycles. I heard that first 6502 models even on dead cycles did garbage R/W operations. I tried to systematize all kinds of dead cycles and ask you to correct my wrong assumptions.
1. All single-byte instructions, even NOP, takes at least 2 cycles. Any single-byte instruction have at least 1 dead cycle. Possible explanation - while CPU busy with decoding of fetched opcode it prefetch next byte for case of there can be operand. But if there is no operands CPU forget this prefetched byte and do not use it for decoding of next instruction. Worst thing in 6502, 1-cycle dex/txa/asl/... would did great boost to total speed. Location of this dead cycle always immediately after first fetch (BRK - fetch,dead,push,push,push,read,read)
2. Any R/W operation (asl mem/dec mem/rol mem/...) add one dead cycle. Immediately before writing cycle, i guess
3. All X/Y indexing modes add 1 dead cycle with one strange exception - "(zp),Y" "abs,X" and "abs,X" have no penalty if it is read-only instruction _and_ adding of X/Y do not change high byte of address. I have no assumption why it is only for this 3 modes, why only on reading and at what location dead cycle happens
4. Conditional branches. When branch not happens there no pealty, only 2 cycles for instruction fetching. When branch happens there 1 dead cycle (why?? why JMP have no dead cycles?) and plus 1 dead cycle if branch change high byte of PC (again same questions. what differenct with JMP?).
5. any POP instruction (PLP, PLA, RTI, RTS) have 1 dead cycle, regardless of number of bytes pulled from stack. PUSH operations have no dead cycles. strange thing
6. and last exceptions. RTS have 2 dead cycles, 1 related to POP and 1 unknown. JSR have 1 dead cycle.
ps. sorry for my english
1. All single-byte instructions, even NOP, takes at least 2 cycles. Any single-byte instruction have at least 1 dead cycle. Possible explanation - while CPU busy with decoding of fetched opcode it prefetch next byte for case of there can be operand. But if there is no operands CPU forget this prefetched byte and do not use it for decoding of next instruction. Worst thing in 6502, 1-cycle dex/txa/asl/... would did great boost to total speed. Location of this dead cycle always immediately after first fetch (BRK - fetch,dead,push,push,push,read,read)
2. Any R/W operation (asl mem/dec mem/rol mem/...) add one dead cycle. Immediately before writing cycle, i guess
3. All X/Y indexing modes add 1 dead cycle with one strange exception - "(zp),Y" "abs,X" and "abs,X" have no penalty if it is read-only instruction _and_ adding of X/Y do not change high byte of address. I have no assumption why it is only for this 3 modes, why only on reading and at what location dead cycle happens
4. Conditional branches. When branch not happens there no pealty, only 2 cycles for instruction fetching. When branch happens there 1 dead cycle (why?? why JMP have no dead cycles?) and plus 1 dead cycle if branch change high byte of PC (again same questions. what differenct with JMP?).
5. any POP instruction (PLP, PLA, RTI, RTS) have 1 dead cycle, regardless of number of bytes pulled from stack. PUSH operations have no dead cycles. strange thing
6. and last exceptions. RTS have 2 dead cycles, 1 related to POP and 1 unknown. JSR have 1 dead cycle.
ps. sorry for my english