Zilog Z80

From Wikipedia, the free encyclopedia

One of the first Z80 microprocessors manufactured; the date stamp is from June 1976.
Enlarge
One of the first Z80 microprocessors manufactured; the date stamp is from June 1976.
A LQFP version of the Z80.
Enlarge
A LQFP version of the Z80.

The Zilog Z80 is an 8-bit microprocessor designed and sold by Zilog from July 1976 onwards. It was widely used both in desktop and embedded computer designs as well as for military purposes. The Z80 and its derivatives and clones make up one of the most commonly used CPU families of all time, and, along with the MOS Technology 6502 family, dominated the 8-bit microcomputer market from the late 1970s to the mid-1980s.

Although Zilog made attempts with 16-bit (Z800 / Z280) and 32-bit (Z380) versions of the 8/16-bit Z80-architecture, these chips never caught on. The company was also trying hard in the workstation market with its Z8000 and 32-bit Z80000 (both technically unrelated to Z80). In recent decades Zilog has concentrated on the ever-growing market for embedded systems, and the most recent Z80-related microcontroller family, the 8/16/24-bit eZ80, a fast Z80 with a linear 16 MB address range has been successful.

Contents

[edit] Brief history and overview

The Z80 came about when Federico Faggin left Intel after working on the 8080, and by July 1976 Zilog had the Z80 on the market. It was designed to be binary compatible with the Intel 8080 so that most 8080 code could run unmodified on it, notably the CP/M operating system.

The Z80's original DIL40 chip package pinout.
Enlarge
The Z80's original DIL40 chip package pinout.

The Z80 offered many real improvements over the 8080:

  • An enhanced instruction set including bit manipulation, block move, block I/O, and byte search instructions
  • New IX and IY index registers and instructions for them
  • A vectorized interrupt mode (mode 2), as well as a useful "no hardware"-mode (mode 1)
  • Two separate register files, which could be quickly switched, to speed up response to interrupts
  • A built-in DRAM refresh address mechanism that would otherwise have to be provided by external circuitry
  • Single 5 Volt power supply
  • Fewer support chips required for clock generation and interface to memory and I/O
  • A much lower price

The Z80 quickly took over from the 8080 in the market, and became one of the most popular 8-bit CPUs. Later versions increased in speed from the early models' 2.5 MHz up to as much as 20 MHz.

Perhaps a key to the success of the Z80 was the built-in DRAM refresh, which allowed systems to be built with fewer support chips.

[edit] Technical Description

[edit] Programming model and register set

The programming model and register set are conventional and similar to many other processors, such as the related x86 family. The 8080 compatible registers AF,BC,DE,HL are duplicated as two separate banks in the Z80, where the processor can quickly switch from one bank to the other; a feature useful for speeding up responses to single level, high priority interrupts. This makes sense as the Z80 (like, for instance, the 6502) was really intended for embedded use, not for personal computers, or the yet-to-be invented home computers.[1]

The 8080 compatible registers:

  • AF - 8-bit accumulator (A) and flag bits (F) carry, zero, minus, parity/overflow, and half-carry (used for BCD)
  • BC - 16-bit data/address register or two 8-bit registers
  • DE - 16-bit data/address register or two 8-bit registers
  • HL - 16-bit accumulator/address register or two 8-bit registers
  • SP - stack pointer, 16 bits
  • PC - program counter, 16 bits

Registers introduced with the Z80:

  • IX - 16-bit index or base register for 8-bit immediate offsets
  • IY - 16-bit index or base register for 8-bit immediate offsets
  • I - interrupt vector base register, 8 bits
  • R - DRAM refresh counter, 8 bits (MSB does not count)
  • AF' - alternate accumulator and flags, also known as shadow registers (toggled in and out with EX AF,AF' )
  • BC',DE', and HL' - alternate registers (toggled in and out with EXX)
  • Four bits of interrupt status and interrupt mode status

There is no direct access to the alternate registers, instead two special instructions, EX AF,AF' and EXX, each toggles one of two multiplexer flipflops; this enables fast context switches for interrupt service routines: EX AF,AF' may be used alone (for really simple and fast interrupt routines) or together with EXX to swap the whole AF,BC,DE,HL set; still much faster than pushing the same registers on the stack (slower, or lower priority, interrupts normally use the stack to store registers).

The refresh register, R, increments[2] each time the CPU fetches an opcode (or opcode prefix) and has therefore no simple relationship with program execution. This has sometimes been used to generate pseudorandom numbers in games, and also in software protection schemes. It has also been employed as a "hardware" counter in some designs; a famous example of this is the ZX81, which lets it keep track of character positions on the TV screen by triggering an interrupt at wrap around (by connecting INT to A6).

The interrupt vector register, I, is used for the Z80 specific mode 2 interrupts (selected by the im 2 instruction). It supplies the base address for a 128-entry table of service routine addresses which are selected via a pointer sent to the CPU during an interrupt acknowledge cycle. The pointer identify a particular peripheral chip and/or peripheral function or event, where the chips are normally connected in a so called daisy-chain for priority resolution. Like the refresh register, this register has also sometimes been used creatively.

[edit] The Z80 assembly language

[edit] Background

The first Intel 8008 assembly language was based on a very simple (but systematic) syntax inherited from the Datapoint 2200 design. This original syntax was later transformed into a new, somewhat more traditional, assembly language form for this original i8008 chip. At about the same time, the assembly language was also extended to accommodate the new addressing possibilities in the more advanced 8080 chip [3].

In this process, the mnemonic L, for load, was replaced by various abbreviations of the words load, store and move, intermixed with other symbolic letters; the mnemonic M, for memory (referenced by HL), was lifted out from within the instruction mnemonic and became an operand; registers also became very inconsistently denoted, sometimes by abbreviated operands (MVI D, LXI H etc), or within the instruction mnemonic itself (LDA, LHLD etc), or both (LDAX B, STAX D etc).

Datapoint 2200
& i8008      i8080         Z80            i8086
(ca -1973)  (ca 1974)     (1976)          (1978)

LBC        MOV B,C      LD B,C           MOV BL,CL

--         LDAX B       LD A,(BC)        MOV AL,[BX]
LAM        MOV A,M      LD A,(HL)        MOV AL,[BP]
LBM        MOV B,M      LD B,(HL)        MOV BL,[BP]

--         STAX D       LD (DE),A        MOV [DX],AL
LMA        MOV M,A      LD (HL),A        MOV [BP],AL
LMC        MOV M,C      LD (HL),C        MOV [BP],CL

LDI 56     MVI D,56     LD D,56          MOV DL,56
LMI 56     MVI M,56     LD (HL),56       MOV byte ptr [BP],56

--         LDA 1234     LD A,(1234)      MOV AL,[1234]
--         STA 1234     LD (1234),A      MOV [1234],AL

--         --           LD B,(IX+56)     MOV BL,[SI+56]
--         --           LD (IX+56),C     MOV [SI+56],CL
--         --           LD (IY+56),78    MOV byte ptr [DI+56],78

--         LXI B,1234   LD BC,1234       MOV BX,1234
--         LXI H,1234   LD HL,1234       MOV BP,1234

--         SHLD 1234    LD (1234),HL     MOV [1234],BP
--         LHLD 1234    LD HL,(1234)     MOV BP,[1234]
--         --           LD BC,(1234)     MOV BX,[1234]
--         --           LD IX,(1234)     MOV SI,[1234]

Illustration of four syntaxes, using samples of equivalent, or (for 8086) very similar, load and store instructions.

[edit] The new syntax

According to Masatoshi Shima, certain people within Zilog wanted a "computer oriented" image for the company, and also felt they needed to "differentiate" their first product from the 8080. Intel had also copyrighted their assembly mnemonics. Yet another assembly syntax was therefore developed, but this time with a more systematic approach:

  • (i) All registers and register pairs are explicitly denoted by their full names
  • (ii) Round brackets are consistently used to state "contents of" (or indirection, or pointer dereferencing)
  • (iii) All load and store instructions uses the same mnemonic name, LD, for load;[4] other common instructions, such as ADD, INC etc, uses the same mnemonic regardless of addressing mode or operand size, this is possible because the operands themselves carry enough information.

These principles made it straighforward to find names and forms for all new Z80 instructions, as well as orthogonalizations of old ones, such as LD BC,(1234) above.

It is interesting to see the resemblance between Z80 and 8086 syntax, as illustrated by the table. Apart from naming differences, and despite a certain discrepancy in basic register structure, the two are virtually isomorphous for a large portion of Z80 instructions.[5]

[edit] Instruction set and encoding

The Z80 uses 252 out of the available 256 codes as single byte opcodes; the four remaining codes are used extensively as opcode prefixes; CB and ED enables extra instructions and DD or FD selects IX+d or IY+d (in some cases without displacement d) in place of HL. This scheme gives the Z80 a large number of permutations of instructions and registers; ZiLOG categorizes these into 158 different "instruction types", 78 of which are the same as those of the Intel 8080 (allowed operation of 8080 programs on a Z80). The ZiLOG documentation further groups instructions into the following categories:

  • 8-bit load
  • 16-bit load
  • Exchange, block transfer, and search
  • 8-bit arithmetic and logic operations
  • General purpose arithmetic and CPU control
  • 16-bit arithmetic
  • Rotate and shift
  • Bit set, reset, and test
  • Jump
  • Call, return, and restart
  • Input and output

The bit set, reset, and test instructions are well adapted to I/O control. No multiply instruction is available in the original Z80. Different sizes and variants of additions, shifts, and rotates have somewhat differing effects on flags because the flag-influencing properties of the 8080 had to be copied for compatibility. Load instructions does not affect the flags (except for the special purpose I and R register loads).

[edit] Undocumented instructions

The index registers, IX and IY, were intended as flexible 16 bit pointers, enhancing the ability to manipulate memory, stack frames and data structures. Officially, they were treated as 16 bit only. In reality, they were implemented as a sort of copy of the HL register which is accessible as 16 bits or as a pair of 8 bit pair registers (H and L). Even the binary opcodes (machine language) were identical, but preceded by a new opcode prefix, as mentioned above. ZiLOG published the opcodes and related mnemonics for the intended functions, but did not document the fact that every opcode that allowed manipulation of the H and L registers was equally valid for the 8 bit portions of the IX and IY registers. As an example, the opcode 26h followed by an immediate byte value (LD H,n) will load that value into the H register. Preceding this two-byte instruction with the IX register's opcode prefix DD, would instead result in the most significant 8 bits of the IX register being loaded with that same value.

There are several other undocumented instructions as well.

[edit] Instruction execution

As in all microprocessors, each instruction is divided into several steps which are usually termed machine cycles (M-cycles). Z80 needs between one and six M-cycles to execute a particular instruction as each M-cycle corresonds roughtly to one memory access and/or internal operation. Many instructions actually end during the M1 of the next instruction which is known as a fetch/execute overlap.

Examples of typical instructions (R=read, W=write)

 Total
M-cycles   instruction           M1        M2         M3         M4         M5           M6

  1         INC A              opcode
  2         ADD A,100          opcode     100
  3         ADD HL,DE          opcode   internal   internal
  4         SET 5,(HL)         prefix    opcode   R(HL), set   W(HL)
  5         LD (IX+102),103    prefix    opcode      102      103,add    W(IX+102)
  6         INC (IY+104)       prefix    opcode      104        add    R(IY+104),inc   W(IY+104)

The Z80 machine cycles are sequenced by an internal state machine which builds each M-cycle out of 3,4, or 5 discrete steps (i.e. clock cycles) depending on context. This avoids cumbersome asynchronous logic and makes the control signals behave consistently at a wide range of clock frequencies. Naturally, it also means that a higher frequency (approximately 2.5 times) crystal must be used than without this subdivision of machine cycles. It does not imply higher requirements on memory access times however, as the Z80 combines at least two full clockcycles to form a long memory access period (the M1-signal) which would typically last only a fraction of a clock cycle in more asynchronous design.

Moreover, affordable memory chips (especially ROM & FLASH) are generally significantly slower than the state machine sub-cycles (clock cycles) used in microprocessors, and the shortest machine cycle time that could safely be used is limited by memory access times in most embedded (and home computer) designs.

[edit] Compatible peripherals

Zilog introduced a number of peripheral parts for the Z80, which all supported the Z80's interrupt handling system and I/O address space. These included the CTC (Counter-Timer-Circuit), the SIO (Serial Input Output), the DMA (Direct Memory Access), the PIO (Parallel Input-Output) and the DART (Dual Asynchronous Receiver Transmitter). As the product line developed, low-power, high-speed and CMOS versions of these chips were produced.

In the same manner as the x86 family, but unlike contemporary 8-bit processors, like the Motorola 6800 and Mos Technology 6502, the Z80 and 8080 had a separate control line and address space for I/O instructions. While some Z80-based computers used "Motorola-style" memory mapped input/output devices, usually the I/O space was used to address one of the many Zilog peripheral chips compatible with the Z80. Zilog I/O chips supported the Z80's new mode 2 interrupts (see description above) which simplified interrupt handling for large numbers of peripherals.

[edit] Undocumented 16 bit I/O-addressing

The Z80 was officially described as supporting 16 bit (64k bytes) memory addressing, and 8 bit (256 ports) I/O-addressing. Looking carefully at the hardware reference manual, it can be seen that several I/O instructions, OUT (C),A for example, assert the contents of the entire 16 bit BC register to the address bus. An orthodox design would maybe decode the entire 16 bit address bus on I/O operations in order to take advantage of this feature, but it has also been used to minimize hardware requirements, see ZX81.

[edit] Second sources, derivatives etc

[edit] Second sources

NEC's μPD780C Z80 clone on a ZX Spectrum board.
Enlarge
NEC's μPD780C Z80 clone on a ZX Spectrum board.
Sharp's LH0080A Z80 clone
Enlarge
Sharp's LH0080A Z80 clone
The T34BM1, a Soviet Z80 clone.
Enlarge
The T34BM1, a Soviet Z80 clone.
The Toshiba TMPZ84C015 - a plain Z80 with many peripheral- and other functions on chip.
Enlarge
The Toshiba TMPZ84C015 - a plain Z80 with many peripheral- and other functions on chip.
Hitachi HD64180
Enlarge
Hitachi HD64180

Mostek MK3880 and SGS-Thompson Z8400 (now ST Microelectronics) were both second-sources for the Z80. Sharp and NEC developed clones in NMOS, the LH-0080 and µPD780C respectively. Toshiba made a CMOS-version, the TMPZ84C00, which is believed (but not verified) to be the same design also used by Zilog for its own CMOS Z84C00. There were also Z80-chips marked GoldStar and LG.

In East Germany, an unlicensed clone of the Z80, known as the U880, was manufactured. It was very popular and was used in Robotron's and VEB Mikroelektronik Mühlhausen's computer systems (e.g. the KC85-series) and also in many self-made computer systems (ex. COMP JU+TER). In Romania could be found another unlicensed clone, named MMN80CPU and produced by Microelectronica, used in home computers like TIM-S, HC, COBRA.

Also, several fully compatible clones of Z80 were created in the Soviet Union, notable ones being the КP1858ВМ1 (there was an unproven rumor that it contains the East-German U880 chip inside) and T34BM1 (this one contains a real Soviet chip inside). Another Soviet CPU, the KP580ИK80 (later marked as KP580BM80), was a clone of the Z80's predecessor, the Intel 8080.

[edit] Derivatives

Currently produced:

  • Hitachi developed the HD64180, a microcoded and partially dynamic CMOS Z80 with on chip peripherals and a simple MMU giving a 1 MB address space. It was later second sourced by Zilog, both as Z64180 and as the slightly modified[6] Z180; since long maintained and further developed under Zilog's name. The newest Z180s are based on the fully static S180/L180 core with very low power draw and EMI (noise).
  • Toshiba developed the 84 pin Z84013 / Z84C13 and the 100 pin Z84015 / Z84C15 series of "intelligent peripheral controllers", basically ordinary NMOS/CMOS Z80 cores with large numbers of Z80 peripherals, watch dog timer, power on reset, and wait state generator on chip; today second sourced by Zilog.
  • The 32-bit Z80 compatible Zilog Z380, introduced 1994, has survived but never gained real momentum; it is used mainly in telecom equipment.
  • Zilog's fully pipelined 8/16/24-bit Z80 compatible eZ80 with a linear 24 MB address space was introduced in 2001 and has been much better received than the Z380; it exists in versions with on chip SRAM and/or flash memory, as well as with integrated peripherals; one variant has on chip MAC (media access controller) and available software include a TCP/IP stack. Contrasting to Z800/Z280, there are only a few added instructions (LEAs and variable-address 16/24-bit loads, basically); the old ones execute much faster instead.
  • The Toshiba TLCS-870, TLCS-90 and TLCS-900 series of high volume (mostly OTP) microcontrollers are based on the Z80; they share the same basic BC,DE,HL,IX,IY register structure, and largely the same instructions, but are not binary compatible.
  • The Chinese Actions Semiconductor's ATJ2085 audio processor chip contains a Z80-compatible MCU together with a 24-bit dedicated DSP processor. The chip is used in a large number of MP3 players and other products.

No longer produced:

  • The ASCII Corporation R800 was a fast 16-bit processor used in certain MSX computers; it was software, but not hardware compatible with the Z80.
  • Zilog's ill-fated NMOS Z800 and CMOS Z280 were quite fast Z80-implementations (before the HD64180 / Z180) with a 24 MB paged MMU address space; they added many orthogonalizations and addressing modes to the Z80 instruction set, but were too complex and mini-computer inspired to be a natural choice for most embedded applications.[7] In contrast, the plain CMOS Z80 has remained popular, alongside the compatible Z180 and eZ80 families.

Some index register instructions in the original Z80 are no faster than equivalent sequences of simpler operations, merely saving space, not time; the 10-year-newer Z180 design could afford more "chip area", permitting a somewhat more efficient implementation (using a wider ALU, among other things). However, it was not until 2001 and the advent of the fast pipelined eZ80 that those instructions finally became approximately as cycle-efficient as it is technically possible to make them, i.e. given the Z80 encodings combined with the capability to do an 8-bit read or write every clock cycle.

[edit] FPGA and ASIC versions

A commercial, functionally equivalent, CPU core is the Evatronics CZ80CPU, available as synthesizable VHDL or Verilog source code, for high volume ASICs, or as post-synthesis EDIF netlists, for low volume FPGAs from Actel, Altera, Lattice or Xilinx.

Free versions are the T80 and TV80, available as VHDL and Verilog sources under a BSD style license. The VHDL version, once synthesized, can be clocked up to 35 MHz on a Xilinx Spartan II FPGA. For large production series, it's much cheaper to use a traditional solution (or ASIC) than an FPGA, however.

[edit] Software emulation

Software emulation of the Z80 instruction set on modern PCs runs faster than the original Z80 CPU ran and is used for home computer simulators (such as ZX Spectrum and Amstrad CPC) and also for video game emulators such as MAME, which executes 1980s vintage video games.

[edit] Notable uses

[edit] In desktop computers

During the late 1970s and early 1980s, the Z80 was used in a great number of fairly anonymous business-oriented machines with the CP/M operating system; a CPU/OS combination that dominated the market in much the same way that Windows based machines do today. Two well-known examples of Z80+CP/M business computers are the portable Osborne 1 and the Kaypro series. Research Machines manufactured the 380Z and 480Z microcomputers which were networked with a thin Ethernet type LAN and CP/NET in 1981. Other manufacturers of such systems included Televideo, Xerox and a number of more obscure firms. Some systems used multi-tasking operating system software to share the one processor between several concurrent users.

Home computers using the Z80 include the following:

For a comprehensive overview, see the List of home computers using the Z80.

  • The Z80 was also used in the Norwegian Tiki 100 computers, which were the computers of choice in Norwegian primary schools during the late 1980s.
  • The Multitech Microprofessor I, introduced in 1981, was designed as a simple and inexpensive training system for the Z80 microprocessor. As of 2005, it was still on market.
  • A Z80A Polish clone was also used in the ZX Spectrum clones produced by Polish company Elwro.
  • In Romania, several Z80 based computers were manufactured: HC85, HC90, HC91, HC2000 (by the Felix Computers Factory, based in Bucharest), CIP-02 and CIP-03 (by the Electronica Factory, located in Bucharest) and TimS (by the Timişoara Technical University).

[edit] In embedded systems and consumer electronics

The Zilog Z80 has long been a popular microprocessor in embedded systems and microcontroller cores, where it remains in widespread use today. The following list provides examples of such applications of the Z80, including uses in consumer electronics products.

Industrial/professional:

Consumer electronics:

Musical instruments etc:

[edit] See also

[edit] Notes and references

  1. ^ According to one of the designers, Masatoshi Shima, the market focus was on high performance printers, high-end cash registers, and intelligent terminals.
  2. ^ While R is an 8 bit register, it wraps around at 128 instead of 256. If the programmer stores a value in the register, its high bit will be preserved regardless of what the CPU does to the remaining 7 bits. Incorrect implementation of this behaviour is a common source of problems when running games on emulated Z80-machines
  3. ^ 8008 and 8080 shared a language subset without being binary compatible; the 8008 was binary compatible with the datapoint 2200 however.
  4. ^ A return to the simplistic Datapoint 2200 vocabulary
  5. ^ Whether this is due to some common influence on both design teams (in addition to 8080), a coincedent, or otherwise, is unknown so far. Surprisingly, only quite superficial similarities (such as the word MOV, or the letter X, for extended register) exists between the 8080 and 8086 assembly languages, despite the fact that 8080 programs can be compiled into x86 code (using a special assembler).
  6. ^ Bus protocol/timing better adapted to Z80 peripheral chips.
  7. ^ Minicomputer features such as, user and system modes, multiprocessor support, on chip MMU, on chip instruction and data cache, etc. was seen rather as more complexity than as functionality and support for the (usually electronics-oriented) embedded systems desiger, it also made it very hard to predict instruction execution times.
  8. ^ The Sinclair ZX80 and -81, and some ZX Spectrums, were equipped with the NEC μPD780C clone of the Z80
  9. ^ The Oberheim OB-8 uses the NEC μPD780C clone of the Z80

[edit] External links

[edit] References

Zilog Components Data Book, Zilog, Campbell California, 1985, no ISBN