EE 323: Microprocessor systems design
2. Z80 hardware and programming model
1. Z80 hardware model
Z80 hardware model shows logic pinout of the chip and how it
communicates with memory and I/Os by using various buses.
The Z80 is an 8 bits microprocessor with 16 address lines. It works with
5v power supply and it’s composed by 40 pin dual in line. Figure 1 show a
pinout and logic signal of a Z80 microprocessor.
Figure 1: Z80 microprocessor Pinout and logic signal
All the signals can be classified into 6 groups (figure 1); address bus, data
bus, control signal, external request, request acknowledge and special signals
and power and frequency signal.
1.1 Address bus
Z80 has a 16 tri-state unidirectional signal lines from A0 to A15, 2 bytes or 16
bits can address 216 or 64k memory registers. It’s used for accessing the memory
registers and I/O devices.
1.2 Data bus
Z80 has 8 tri-state bidirectional lines from D0 to D7. It’s used for transferring
data (input, output) between memory and I/Os devices.
1.3 Control signal
The control signal is composed by five individual output lines:
-Machine cycle one (̅̅̅̅̅: it’s an active low signal, it indicates that an opcode is
being fetched from memory.
-Memory Request (̅̅̅̅̅̅̅̅̅): it is an active low tri state signal, indicating that a
valid address for memory read and write operation is grasped by the address bus.
-Input/output Request (̅̅̅̅̅̅̅ : it’s an active low tri state line, indicating that a
valid address for an I/O read and write operation is grasped by the low order
address bus (A7-A0). This signal is also generated for an I/O Request.
-Read (̅̅̅̅ : it’s an active low tri state line, indicating that the microprocessor
is ready to read data from memory or an I/O device. This signal should be used
with memory request and I/O request.
-Write (̅̅̅̅̅ : it’s an active low tri state line, indicating that the microprocessor
is ready to write data into memory or an I/O device. This signal should be used
with memory request and I/O request.
1.4 External request
The external request includes five different input signals. It’s used to interrupt
an ongoing process and to request the microprocessor to do something else.
-Reset (̅̅̅̅̅̅̅̅̅̅̅: it is an active low signal, used to reset the microprocessor, it
means, the memory refresh R and the programme counter PC and the interrupt
register I are all cleared to zero. The reset signal can be initiated by an external
key or switch. It needs at least three clock periods to complete the reset
operation.
-Interrupt Request (̅̅̅̅̅): it’s an active low signal; initiated by an I/O device
for interrupting the microprocessor operation.
-Nonmaskable interrupt ̅̅̅̅̅̅ (: it cannot be disabled, it activated by an
external source. This signal is used for implementing emergency procedure.
-Bus request (̅̅̅̅̅̅̅̅̅̅ : it’s an active low signal, initialized by an external
devices. This device sends a low signal to bus request to request the use of the
address bus and data bus and the control signals. The microprocessor
recuperates the control at the end of the operation.
-Wait (̅̅̅̅̅̅̅̅ : it’s an active low signal, used by memory and I/O device to add
clock cycles to extend the Z80 operations.
1.5 Request Acknowledge and Special Signals
–Bus Acknowledge ̅̅̅̅̅̅̅̅̅̅ : an active low signal initiated by Z80 in response
to ̅̅̅̅̅̅̅̅̅̅. This signal indicates to the requesting device that the address bus,
the data bus, and the control signals have entered into the high impedance state
and can be used by the requesting device.
– Halt (̅̅̅̅̅̅̅̅ : it’s an active low signal to indicate that μP has executed the
HALT instruction.
- Refresh ̅̅̅̅̅̅̅̅ : it’s an active low signal indicate that the low order 7 bits
from address bus A6- A0 holds a refresh address from memory; it should be
used in conjunction with MREQ to refresh memory contents.
1.6 Power and Frequency Signals:
This group includes three signals as follows:
– Clock: This pin is used to connect a single phase frequency source.
– +5V and GND - These pins are for a power supply and ground reference.
2. Z80 programming model
To Process data internally, the microprocessor should include the following:
- instruction decoder to decode the binary information
- registers to store binary data
- register to store address memory register
- Arithmetic and Logical unit to to perform arithmetic and logical operation
- Flags or flip flops to indicate data condition for decision making
Figure2: internal structure of microprocessor
The Z80 programming model is used to represent the internal structure of the
Z80 microprocessor. Figure 3 show such model, which include accumulator,
flag register, and general purpose register, registers as memory pointer and
special purpose register.
Figure 3: The Z80 programming model.
Figure shows the Z80 programming model to represent the internal structure
which is composed of:
2.1. Accumulator
The accumulator is an 8bit register called register A. This register is used to
store 8 bits data and perform arithmetic and logical operation. The result of an
operation performed by the arithmetic and logical unit (ALU) is stored in the
accumulator. For example, in an 8bit addition, the instruction ADD always
assumes that one of numbers is byte in the accumulator and the result of addition
is stored in the accumulator by replacing the previous byte.
2.3 Flag register
The ALU comprises six flags. After each ALU operation, the flags are set or
reset according to data conditions. The status of each of the six flags is stored in
the 8bit flag register so that they can be examined if necessary. Figure 4 show
the bit position of each flag in the flag register:
- S (Sign): after an ALU operation, in case of signed number, if the most
significant bit D7 is 1, the sign flag is set, otherwise it is reset.
- Z (Zero): set if result is zero, reset otherwise.
- C (Carry): bit D0 is set if an arithmetic operation generates a carry
(addition) or borrow (subtraction), reset otherwise.
- P/V (Parity or Overflow): set if the number of 1s in the result is even,
reset if odd. Set if Overflow.
- H (Half-Carry): set if there is a BCD carry/borrow from D3 to D4, reset
otherwise.
- N (Add or Subtract): set for BCD subtraction, reset for BCD addition.
Figure 4: Flag register. Bit identification.
Example: after an addition the result generate a carry flag C will be set and D0
will show logical 1.
D5 and D3 are unused. The Half-Carry (H) and Add or Subtract (N) flags are
used internally by the microprocessor for Binary Coded Decimal (BCD)
operations.
The H and N flags cannot be tested by any instruction and are not available to
the programmer for decision making.
The flags S, Z, P/V and C can be tested in conjunction or with condition jump or
call instruction, each of these four flags has two Jumps or call instruction: one
when the flag is set and the other when the flag is reset. These flags are critical
importance in the decision making process (chapter 3 provide greater details).
2.4 General-Purpose Registers
Z80 contain six programmable 8-bit registers: B, C, D, E, H, and L. These 8 bit
registers are used for storing data during the program execution. They can be
combined as register pairs: BC, DE, and HL to perform 16-bit operations or to
hold addresses. The programmer can use these registers to load or copy data.
2.5 Alternate Registers
The Z80 includes a similar set of alternate registers designated as B’, C’, D’, E’,
H’, L’, A’, and flag F’. These registers are not directly available to the
programmer; however, the exchange instructions can exchange information of
register pairs with the respective alternate register pairs.
Example: B’ and A’ used to handle interrupt in order to quickly save the
current working data inside the registers.
2.6 16-bit Registers
Z80 contain four 16 bit registers, used to hold memory addresses as memory
pointers. This memory pointer provides address to the microprocessor in order
to access a byte in memory location.
- Index Registers (IX and IY): used to store 16-bit addresses and to
identify memory locations for data transfer.
- Stack Pointer (SP): used to point to the memory location called the
stack.
- Program Counter (PC): functions as a 16-bit counter, it’s used to
sequence the execution of instructions. The function of the PC is to point
to the memory address from which the next byte is to be fetched, after that
the microprocessor increments the program counter by one to point the
next memory location.
2.7 Special-Purpose Registers
Z80 contain two special purpose register, Interrupt Vector register (I) and
Memory Refresh register (R).
- Interrupt Vector register: It’s an 8bit register, used in the interrupt
process. It’s used to store the high order eight bits of 16 bit address.
- Memory refresh register: It’s an 8bit register, used as 7bit counter to
provide an address of memory cells to be refreshed in dynamic memory.