3 ms·
> I still prefer programming the Z80 over the 6502 though :) I really don't. There are some few things you can fit into and get working fast in the Z80's A +
by brucehoult 1mo ago
> I still prefer programming the Z80 over the 6502 though :)
I really don't.
There are some few things you can fit into and get working fast in the Z80's A + 6 registers (IX and IY are not useful if speed is the aim), but for anything complicated the 6502's 256 Zero page locations — any pair of which can hold a pointer you can index off — is far superior.
The Z80 is awful at accessing memory for anything other than a simple absolute address or sequential access or push/pop of a register pair. It's better for manipulating 16 bit values, but not as much as you'd think especially once you run out of three register pairs plus ToS.
- userbinator 1mo agoThe 6502 doesn't even have much of a stack.
- brucehoult 1mo agoThe 256 byte hardware stack is plenty for function return addresses and temporary use within a function. How deep are you planning to nest function calls anyway? You can create as many other stacks as you want using pairs of Zero Page locations as stack pointers. Best practice for recursive/reentrant code (e.g. compiling C) is to follow modern RISC/x86_64 practice and reserve a few (16 maybe) Zero Page locations as argument/working registers, a few (16 maybe) as callee-save registers, and have prolog and epilog utility functions that create/destroy a stack frame and save/restore N bytes of callee-save ZP locations. You can unroll those into a sequence of elements like... lda $1F dey sta (SP),y lda $1E dey sta (SP),y : lda $10 dey sta (SP),y ... at 5 bytes and 11 cycles per byte saved. And of course jump into the appropriate part of the sequence.
- flohofwoe 1mo agoIn the end, you could do memory load/stores with around 1 byte per microsecond on most home computers, no matter if 6502 or Z80. The Z80 did less work per clock, but was usually clocked 2..4x higher than 6502 based systems, which made up for the higher instruction cycle counts (the 2 MHz 6502 systems might have a slight edge against a 4 MHz Z80, but it wasn't night and day, and the C64 got away with its 1 MHz clock because the CPU was more or less just a controller for the various custom chips).