Linked by Thom Holwerda on Sat 7th Sep 2013 09:54 UTC
Hardware, Embedded Systems

The 8-bit Z-80 processor is famed for use in many early personal computers such the Osborne 1, TRS-80, and Sinclair ZX Spectrum, and it is still used in embedded systems and TI graphing calculators. I had always assumed that the ALU (arithmetic-logic unit) in the Z-80 was 8 bits wide, like just about every other 8-bit processor. But while reverse-engineering the Z-80, I was shocked to discover the ALU is only 4 bits wide! The founders of Zilog mentioned the 4-bit ALU in a very interesting discussion at the Computer History Museum, so it's not exactly a secret, but it's not well-known either.

I have been reverse-engineering the Z-80 processor using images from the Visual 6502 team. The image below shows the overall structure of the Z-80 chip and the location of the ALU. The remainder of this article dives into the details of the ALU: its architecture, how it works, and exactly how it is implemented.

Ken Shirrif's blog is an absolute must for fans of ultra-low-level hardware stuff. This goes way over my head, but interesting nonetheless.

Thread beginning with comment 571644
To view parent comment, click here.
To read all comments associated with this story, please click here.
bartgrantham
Member since:
2011-12-31

Just playing devil's advocate, but the Z-80 could also do 16-bit adds and substracts the the HL/BC/DE register pairs. Wouldn't that make it a 16-bit CPU by your definition (width of operands)?

Reply Parent Score: 5

Alfman Member since:
2011-01-28

bartgrantham,

I agree. Consider that one could hypothetically implement/emulate a 64bit ISA CPU on top of 16bit components, but personally I still think it makes sense to call it a 16bit CPU if it can only ever physically handle 16 bits concurrently.

Admittedly though it's rather ambiguous when different components (and operations) have different bit widths (register bits/cpu&cache bus width/memory&device bus width/alu/fpu/...). Maybe in such circumstances it makes the most sense to call the Z80 a 4/8bit hybrid rather than either 4bit or 8bit.

Edited 2013-09-09 17:34 UTC

Reply Parent Score: 3

Drumhellar Member since:
2005-07-12

Perhaps, but considering how limited using register pairs is compared to the rest of the architecture, I'd still say it's 8-bit. I mean, I wouldn't call the Pentium MMX a 64-bit chip simply because it can do 64-bit integer math - the conditions imposed to adding large numbers is quite extensive.
Also, if you look at the bitwise or logical operators, they are only capable of operating on one register at a time, with the exception of the HL pair.

Of course, I don't have any actual experience programming a Z-80, but everybody calls it 8-bit, and the instructions listed at http://bit.ly/14z9vLR show it's almost pure 8-bit instructions, with a couple special 16-bit instructions.

I do know the Nintendo Gameboy used the a variation of the Z-80, and that was considered an 8-bit system by Nintendo.

(According to Wikipedia, the chip in the Gameboy was somewhere between the 8080 and the Z-80, with none of the extra registers of the Z-80, but many of the extra instructions. It's not pure Z-80, but most sources I've seen consider it one)

Reply Parent Score: 4

Alfman Member since:
2011-01-28

Drumhellar,

"I wouldn't call the Pentium MMX a 64-bit chip simply because it can do 64-bit integer math - the conditions imposed to adding large numbers is quite extensive."

This is somewhat tangential, but it may interest you anyways...MMX wasn't actually capable of 64bit integer math. It's 64bit registers were actually split up into multiple packed operands of 32bits or less. At 32bit it was limited to addition and subtraction. It could only do 16 bit multiplications (_mm_mulhi_pi16). I remember back in the day learning MMX but being very disappointed in what it offered. Complete 32bit SIMD support wasn't available until some time later with SSE. IMHO SSE2 was the first truly useful (intel) SIMD extension for x86, not only because it offered 128bit XMM registers (64bit operations), but because it finally stopped clobbering the FPU registers which was a hack.


http://www.plantation-productions.com/Webster/www.artofasm.com/Wind...

"Despite the presence of 64-bit registers, the MMX instruction set does not extend the 32-bit Pentium processor to 64-bits. Instead, after careful study Intel added only those 64-bit instructions that were useful for multimedia operations. For example, you cannot add or subtract two 64-bit integers with the MMX instruction set. In fact, only the logical and shift operations directly manipulate 64 bits."

https://en.wikipedia.org/wiki/Streaming_SIMD_Extensions

Reply Parent Score: 2

DeepThought Member since:
2010-07-17

IMHO neither the bus width nor the ALU was used to "define" the bitness of a CPU. It was the register width.

The 68k was seen as a 32bit CPU, but then people claim it a 32/16bit CPU because the data-bus with was only 16bit (or even 8 on a 68008 (Sinclair QL)).

But today this definition is also not that easy to use. For example, the e200 PowerPC cores have 64bit registers, but only for SIMD (SPE called by Freescale). So no real 64bit add possible. So it is a 32bit CPU.

So IHMO, today, the bitness is defined by the width of general purpose registers.

Reply Parent Score: 2

JLF65 Member since:
2005-07-06

To software engineers, the "bitness" is defined by the ISA, and is nearly always the width of operational data registers (registers that can be added, multiplied, etc).

To hardware engineers, the bitness is defined by the width of the ALU. The 68000 was the classical case - it had a 32-bit architecture, but the ALU was only 16 bits wide. It was commonly noted as a 16/32 bit processor. At the time, hardware engineers had more sway in computers, so the 68000 was in most books as a 16 bit processor, along with the 8086.

This new info on the Z80 would have had most engineers of the time calling it a 4-bit CPU, so it's no wonder Zilog kept this quiet. They were competing in the 8-bit CPU market, and being called a 4-bit processor, or at best a 4/8 bit processor would have meant death in the marketplace.

Reply Parent Score: 3