On 04/21/2024 7:06 PM CDT Peter Coghlan via cctalk
<cctalk(a)classiccmp.org> wrote:
Why is that? Did the Z80 take more cycles to implement it's more complex
instructions? Is this an early example of RISC vs CISC?
Regards,
Peter Coghlan
I'm certainly no authority, but I have programmed both processors in assembly and
studied them somewhat. It took many years for me to believe that the 6502 was
"faster" than the Z80, but now I'm (mostly) a believer. So here is my
take.
First, yes, the Z80 takes roughly 4 times as many clock cycles per instruction. Where the
6502 can complete a simple instruction in a single clock, the Z80 takes a minimum of
four.
The 02 certainly has a simpler architecture, but calling it a RISC machine would probably
make the RISC believers cringe. It is simple, but it doesn't follow the pattern of
lots of registers (well, maybe) and a load/store architecture. But that may be its
strongest point. The zero page instructions effectively make the first 256 bytes of RAM
into a large (128 or 256) register file.
Along with all those pseudo-registers in page zero, the 02 has some really nice addressing
modes. In effect, all those pseudo registers can be used as index registers in addition
to directly holding operands. The simple, fast instructions operating on 8 bit registers
runs fast. In the Z80, there are a fair number of registers, but most are limited to what
they can be used for. You almost always have to go through the accumulator (register A.)
So you end up moving stuff between memory and various registers, often shuffling stuff
around once loaded, then store it back to memory. The Z80 has the IX and IY index
registers, but they are even slower, adding another machine cycle (4 clocks?) to an
already slowish instruction just for the fetch, then another memory cycle. If you have to
load the operand then store the result, that doubles the extra time needed.
So all of that leads to faster assembly language on the 02. Good 6502 programmers
(I'm NOT one of them) know tons of tricks to get the most out of it, too. People
spent years learning the ins and outs of that particular processor. I think the Z80
didn't get that kind of love, at least not as much. Most Z80 machines were running
CP/M and most didn't have the graphics and sound that made the 02 machines no nice for
home computers and games. In addition, an awful lot of Z80 code/programmers were part
time, moving to and from the 8080 which was really a different machine.
As a rough approximation I would say that a Z80 would require somewhere between 4 to 8
times the clock for equivalent assembly language performance. No doubt others will have
other opinions.
However, the Z80 was probably more likable by the computer science people. And it was a
LOT easier to write a halfway decent compiler for. It didn't need as many
"tricks" to make it perform. If you look at compiled code for the two, you will
usually either find severe limitations on the 02 or very slow code. Especially if you are
looking at any "modern" language (Algol family, such as C or Pascal.) A BASIC
(or perhaps even Fortran) compiler that doesn't have all the local variables and
nested structure will usually fare better.
Anyway, that's my 1/2 cent worth. Take it for what its worth.
Will
Grownups never understand anything by themselves and it is tiresome for children to be
always and forever explaining things to them,
Antoine de Saint-Exupery in The Little Prince