cjs wrote:
dmsc wrote:
The main problem with many registers is that you need to save the registers on interrupts (making interrupts slow)....
Well, no you don't. That's purely a design decision, and I would consider it one of the brilliant innovations in the 6502 that it
doesn't save the entire register file when responding to an interrupt.
Apparently I'm not alone in this; the designers of the 6809 liked the idea enough that they added a second maskable interrupt, FIRQ, that worked in the same way.
Indeed, its such a good idea that ARM and x86 behave essentially the same way: they save (via one method or another) only those registers that
must be saved, and leave the ISR itself to save any others that it needs to use. Of course, in practice, you'll need to save at least one or two general purpose registers or your ISR is unlikely to be able to do anything useful (in the case of 6502, I would say at least the accumulator and one index register), but you as the programmer get to decide what resources you need and what the trade-off is versus the required interrupt servicing delay. For example, I doubt that
any ARM ISR actually saves all 14 general purpose registers since for the types of jobs you should be doing in an ISR that would be pointless: I've seen entire ARM software packages that never touch some of the registers
at all, let alone in an ISR, because there just aren't that many variables that need to be loaded into the CPU at any given moment. Now that I think about it, if you have some spare registers that you're not otherwise using, that'd be a really good way to
speed up your ISR: just have it use those registers that the rest of the software doesn't use, that way you never have to worry about saving and restoring them at all (unless you need the ISR to be re-entrant).
All that being said, in the specific case of the 6502 architecture I feel like it would be nice if the interrupt process saved and restored the accumulator for you because there is essentially no way of doing anything useful without it and it would save a couple of cycles per interrupt. I vaguely remember reading somewhere that it was originally intended that it would but the necessary circuitry wouldn't fit or some such.
_________________
Want to design a PCB for your project? I strongly recommend
KiCad. Its free, its multiplatform, and its easy to learn!
Also, I maintain KiCad libraries of
Retro Computing and
Arduino components you might find useful.