The Z80 Microprocessor: A Comprehensive Tutorial and Biography
Introduction
The Zilog Z80 microprocessor is an iconic piece of technology that played a pivotal role in the evolution of personal computing and embedded systems. Introduced in 1976, the Z80 became one of the most widely used and influential microprocessors of its time. This tutorial and biography delve into the history, architecture, instruction set, and lasting impact of the Z80 microprocessor.
Part I: Biography of the Z80
1. Origins and Development
a. Founding of Zilog
In the early 1970s, the microprocessor industry was burgeoning with innovation. Federico Faggin, an Italian physicist and engineer, was instrumental in designing the Intel 4004 and 8080 microprocessors. Seeking to push the boundaries further, Faggin, along with Ralph Ungermann, left Intel in 1974 to found Zilog, Inc., with the vision of creating a superior microprocessor.
b. Design Goals
The primary objectives for the Z80 were:
- Enhanced Instruction Set: Improve upon the Intel 8080's capabilities.
- Backward Compatibility: Ensure compatibility with existing 8080 software.
- Integrated Features: Incorporate features that reduced the need for external components, such as DRAM refresh.
2. Introduction to the Market
Released in July 1976, the Z80 quickly gained traction due to its superior features and competitive pricing. Its compatibility with the Intel 8080 allowed software developers and system manufacturers to transition smoothly, making it an attractive choice for a wide range of applications.
3. Adoption in Personal Computers
The late 1970s and early 1980s saw an explosion of personal computers, many of which were powered by the Z80. Notable examples include:
- Tandy TRS-80: One of the first mass-produced personal computers.
- Sinclair ZX Spectrum: A popular home computer in the UK and Europe.
- Amstrad CPC: Known for its integrated design with a built-in tape drive or disk drive.
These systems brought computing to the masses, and the Z80 was at their core, handling tasks ranging from word processing to gaming.
4. Role in Gaming Consoles and Arcade Machines
Beyond personal computers, the Z80 found a home in gaming consoles and arcade systems. Sega's Master System and Game Gear, as well as numerous arcade machines, utilized the Z80 for sound processing or as the main CPU, demonstrating its versatility.
5. Variants and Enhancements
Over the years, Zilog introduced several variants of the Z80 to cater to evolving market needs:
- Z80A, Z80B, Z80H: Offered higher clock speeds.
- Z180: Integrated additional peripherals.
- eZ80: A 24-bit addressable microprocessor, maintaining backward compatibility.
These enhancements ensured that the Z80 remained relevant in various applications, from embedded systems to educational tools.
6. Legacy and Impact
The Z80's influence is undeniable. Its design philosophy of backward compatibility combined with enhanced features set a precedent in microprocessor development. Even today, the Z80 is used in embedded systems, hobbyist projects, and educational platforms, a testament to its enduring design.
Part II: Tutorial on the Z80 Microprocessor
1. Architectural Overview
a. Core Specifications
- Data Bus Width: 8-bit
- Address Bus Width: 16-bit (allowing 64KB of addressable memory)
- Clock Speeds: Initially 2.5 MHz (Z80), with variants reaching up to 20 MHz (eZ80)
b. Register Set
The Z80 boasts a rich set of registers:
- General Purpose Registers: B, C, D, E, H, L (can form BC, DE, HL pairs)
- Accumulator and Flags: A (Accumulator), F (Flags)
- Alternate Register Set: A', F', B', C', D', E', H', L' (used for fast context switching)
- Index Registers: IX, IY (16-bit, used for advanced addressing modes)
- Stack Pointer (SP): Points to the top of the stack.
- Program Counter (PC): Points to the next instruction.
- Interrupt Page Address (I): Used in interrupt mode 2.
- Refresh Register (R): Assists in DRAM refresh cycles.
c. Memory and I/O
- Memory Addressing: 64KB addressable space.
- I/O Addressing: Separate 16-bit I/O address space, accessed via IN and OUT instructions.
2. Instruction Set Overview
The Z80's instruction set is an extension of the Intel 8080's, offering over 1,500 instructions. Key categories include:
- Data Transfer: LD (Load), EX (Exchange), PUSH, POP
- Arithmetic and Logic: ADD, ADC, SUB, SBC, AND, OR, XOR, CP (Compare)
- Increment/Decrement: INC, DEC
- Rotate and Shift: RL, RR, SLA, SRA, SRL
- Bit Manipulation: BIT, SET, RES
- Control Flow: JP (Jump), JR (Jump Relative), CALL, RET, DJNZ (Decrement and Jump if Not Zero)
- Input/Output: IN, OUT
- Block Instructions: LDIR (Load Increment and Repeat), CPIR (Compare Increment and Repeat), etc.
3. Addressing Modes
The Z80 supports several addressing modes, enhancing its flexibility:
- Immediate: Operand is part of the instruction. e.g., `LD A, 0x3E`
- Register Direct: Operand is in a register. e.g., `ADD A, B`
- Register Indirect: Operand is in memory pointed to by a register pair. e.g., `LD A, (HL)`
- Indexed: Uses IX or IY with displacement. e.g., `LD A, (IX+5)`
- Relative: For short jumps. e.g., `JR NZ, label`
4. Sample Assembly Program
Objective:
Add two numbers stored in memory locations `0x8000` and `0x8001`, and store the result in `0x8002`.
Code:
LD HL, 0x8000 ; Load address 0x8000 into HL
LD A, (HL) ; Load value at 0x8000 into A
INC HL ; HL now points to 0x8001
ADD A, (HL) ; Add value at 0x8001 to A
INC HL ; HL now points to 0x8002
LD (HL), A ; Store result in 0x8002
HALT ; Stop execution
Explanation:
1. LD HL, 0x8000: Initializes the HL register pair to point to the first operand.
2. LD A, (HL): Loads the value at the memory address pointed to by HL into the Accumulator.
3. INC HL: Moves HL to point to the second operand.
4. ADD A, (HL): Adds the second operand to the Accumulator.
5. INC HL: Moves HL to the destination address.
6. LD (HL), A: Stores the result at the destination.
7. HALT: Halts the processor.
5. Interfacing with Memory and Peripherals
a. Memory Mapping
Designing systems with the Z80 involves mapping ROM, RAM, and peripherals within the address space. A common approach is:
- Lower Memory (e.g., 0x0000 - 0x3FFF): ROM for bootloader or firmware.
- Upper Memory (e.g., 0x4000 - 0xFFFF): RAM for data and program execution.
b. I/O Mapping
Peripherals are accessed via the I/O address space using the IN and OUT instructions. For example, to read a byte from an input port `0x10`:
IN A, (0x10) ; Read from port 0x10 into A
To write a byte to an output port `0x20`:
LD A, 0xFF ; Load 0xFF into A
OUT (0x20), A ; Write A to port 0x20
6. Interrupt Handling
The Z80 supports three interrupt modes:
- Mode 0: The interrupting device places an instruction on the data bus.
- Mode 1: The processor jumps to a fixed address (`0x0038`) upon an interrupt.
- Mode 2: The most sophisticated mode; the processor forms the interrupt vector by combining the I register with a value provided by the interrupting device.
This flexibility allows for complex interrupt handling schemes suitable for various applications.
7. Development Tools
Several assemblers and development environments support Z80 programming:
- TASM (Table Assembler): Popular for cross-assembling Z80 code.
- Zilog Developer Studio (ZDS): Official development suite from Zilog.
- SJASMPlus: An open-source Z80 assembler with modern features.
Emulators like EightyOne and MAME allow testing and debugging of Z80 code without physical hardware.
Conclusion
The Zilog Z80 microprocessor stands as a monumental achievement in computing history. Its thoughtful design, combining backward compatibility with innovative features, facilitated its widespread adoption across various platforms. From personal computers and gaming consoles to embedded systems and educational tools, the Z80's versatility and reliability have left an indelible mark on the electronics landscape.
Even decades after its introduction, the Z80 continues to be celebrated by enthusiasts, educators, and engineers alike, serving as both a tool for learning and a testament to timeless engineering.
---
References
1. Zilog Z80 Official Documentation: https://www.zilog.com/
2. Programming the Z80" by Rodney Zaks: A comprehensive guide to Z80 programming.
3. Wikipedia - Zilog Z80: https://en.wikipedia.org/wiki/Zilog_Z80
4. The Art of Assembly Language Programming" by Randall Hyde: While focusing on x86, provides insights applicable to assembly programming in general.