Due to its simplicity it's a fun little processor to program. Hacking on some assembly on a ZX spectrum emulator is a nice way to stay sane in this high abstraction LLM age.
"Simple" is really not a word I would associate with the Z80 ;)
The ISA is quite messy because of the backward compatibility requirement with the Intel 8080 (e.g. the Z80 had to fill undocumented gaps in the 8080 opcode encoding map with new instructions, four of which were prefix instructions to unlock additional instruction 'subsets' (DD/FD for replacing instructions involving the HL register pair with indexed addressing modes via the IX/IY registers, and ED/CB prefixes for adding two entirely new opcode blocks).
If the Zilog engineers would have been free to design their own ISA I'm sure they would have been able to come up with a much more elegant design.
Also the Z80 had more than twice as many transistors as the 6502 (8500 for the Z80 vs 3500 for 6502).
I still prefer programming the Z80 over the 6502 though :)
I am simplifying a lot since there were much more chips involved... but 3500 transistors to have countless hours of fun to play NES games really puts things into perspective
My 5090 has 92 billion transistors (I dont say they dont bring fun)
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.
In 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).
The 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.
If the Zilog engineers would have been free to design their own ISA I'm sure they would have been able to come up with a much more elegant design.
That's an interesting idea. They were previously part of the team that designed the 8080 so they must have been very familiar with the ISA and the design philosophy.
I'm sure they'd be able to come up with improvements but how much more elegant it would have been is hard to say.
Making it even harder to say: the 8080 was based on the 8008. Even though the 8080 was based on the same instruction set as the 8008, it wasn't binary compatible. I assume that means the instruction encoding was different, which means those engineers probably did as much as the could to clean things up while designing the 8080.
Of course, the 8008's origins (along with the completely unrelated 4004) were outside of Intel. They were hired to design custom ICs. The 8008's architecture was dictated by a CTC terminal. While Intel designed the 4004, it was only intended to be used in calculators. Intel, and its engineers, probably put relatively little thought into microprocessor architecture until the 8080.
I cut my teeth writing assembly on a ZX Spectrum (mostly hacking games for infinite lives, etc).
Over the past couple of years I've gone back to the Z80, working on CP/M emulation, testing, and similar things. It's fun to play the old infocom games, and mess around with BIOSes when all you have is 64k.
There's a lot of good CP/M reference material out there, and numerous emulators to run it on modern systems
Comments
Due to its simplicity it's a fun little processor to program. Hacking on some assembly on a ZX spectrum emulator is a nice way to stay sane in this high abstraction LLM age.
"Simple" is really not a word I would associate with the Z80 ;)
The ISA is quite messy because of the backward compatibility requirement with the Intel 8080 (e.g. the Z80 had to fill undocumented gaps in the 8080 opcode encoding map with new instructions, four of which were prefix instructions to unlock additional instruction 'subsets' (DD/FD for replacing instructions involving the HL register pair with indexed addressing modes via the IX/IY registers, and ED/CB prefixes for adding two entirely new opcode blocks).
If the Zilog engineers would have been free to design their own ISA I'm sure they would have been able to come up with a much more elegant design.
Also the Z80 had more than twice as many transistors as the 6502 (8500 for the Z80 vs 3500 for 6502).
I still prefer programming the Z80 over the 6502 though :)
I am simplifying a lot since there were much more chips involved... but 3500 transistors to have countless hours of fun to play NES games really puts things into perspective
My 5090 has 92 billion transistors (I dont say they dont bring fun)
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.
In 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).
The 6502 doesn't even have much of a stack.
The 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...
... at 5 bytes and 11 cycles per byte saved. And of course jump into the appropriate part of the sequence.That's an interesting idea. They were previously part of the team that designed the 8080 so they must have been very familiar with the ISA and the design philosophy.
I'm sure they'd be able to come up with improvements but how much more elegant it would have been is hard to say.
Making it even harder to say: the 8080 was based on the 8008. Even though the 8080 was based on the same instruction set as the 8008, it wasn't binary compatible. I assume that means the instruction encoding was different, which means those engineers probably did as much as the could to clean things up while designing the 8080.
Of course, the 8008's origins (along with the completely unrelated 4004) were outside of Intel. They were hired to design custom ICs. The 8008's architecture was dictated by a CTC terminal. While Intel designed the 4004, it was only intended to be used in calculators. Intel, and its engineers, probably put relatively little thought into microprocessor architecture until the 8080.
They did eventually design their own clean-sheet instruction set for Z8000.
Since Zilog was founded by former Intel engineers, they were probably the ones who helped design the 8080 in the first place?
I cut my teeth writing assembly on a ZX Spectrum (mostly hacking games for infinite lives, etc).
Over the past couple of years I've gone back to the Z80, working on CP/M emulation, testing, and similar things. It's fun to play the old infocom games, and mess around with BIOSes when all you have is 64k.
There's a lot of good CP/M reference material out there, and numerous emulators to run it on modern systems