Microprocessors · Lecture Notes

Chapter 10.1: 8086 Pins

The effect of an assembly instruction on registers and flags is the face the programmer sees. The same instruction also leaves a trace outside the chip: address, data and control signals appear on the pins in a definite order. These notes treat the 8086 as a circuit component. They divide the pins of the 40-pin package into groups and explain how address and data pass through the same pins. They examine, at the level of clock cycles, the address latches and data transceivers that undo the multiplexing, the even and odd memory banks, and the read and write bus cycles. They go on to cover the wait states that slow memory requires, the handing over of the bus to another master, the clock and reset circuit, the 8288 bus controller in maximum mode, and the interrupt pins. In every topic, code traces show which value an instruction produces on which pin.

Learning outcomes

Recognize the pins
Divide the 40 pins of the 8086 into groups; state each pin's direction, its active level and what it carries in which T state; match the eight pins that change between minimum and maximum mode.
Undo the multiplexing
Explain why address and data pass through the same pins; draw how separate address and data buses are built with ALE, an address latch and a data transceiver.
Select the banks
Explain how BHE' and A0 select the even and odd banks; find how many data bus cycles an instruction needs and over which lines the data passes.
Trace the bus cycle
Trace the read and write cycles signal by signal through the states T1–T4; explain how READY adds wait states and compute the number of wait states a memory needs.
Read the status and control pins
Decode the S2'–S0', S3–S6 and QS1–QS0 codes; give the values that RD', WR', M/IO', DT/R', DEN', HOLD/HLDA, RQ'/GT and LOCK' take during an instruction.
Build the system
Explain the role of the 8284A clock generator, the start-up after RESET, the 8288 bus controller and the INTR, NMI and INTA' pins in an 8086 system.

10.1.1The 8086 package and its pins

A microprocessor talks to the outside world only through its pins. Reading a byte from memory, writing a value to a port, receiving an interrupt request or taking in the clock signal each needs a separate electrical connection. The room set aside for these connections on the 8086 is very tight: the whole processor is squeezed into a 40-pin package. This section introduces the package, the naming of the pins and the pin groups. It then shows why 40 pins are not enough. Intel overcame this shortage in two ways: it used the same pin for different purposes at different times, and it tied the meaning of one group of pins to the type of system.

10.1.1.1The 40-pin DIP package

The Intel 8086 is a 16-bit microprocessor made in HMOS (high-performance n-channel MOS) technology. The chip sits inside a rectangular package called a dual in-line package (DIP). Each of the two long sides of the package has twenty pins. The pins are numbered starting from the top-left corner and going counterclockwise: 1–20 from top to bottom on the left side, 21–40 from bottom to top on the right side. A semicircular notch on the top edge of the package marks the position of pin 1.

The 8086 works from a single +5 V supply. The supply is connected to pin 40 (VCC) and ground to pins 1 and 20 (GND). The data sheet allows a tolerance of ±10% on the supply: between 4.5 V and 5.5 V the chip works correctly. A 5 MHz 8086 draws at most 340 mA; that is 5 V × 0.34 A = 1.7 W of power. This power, which looks small by today's standards, was a serious figure for heating the chip in 1978.

max mode(min.)8086CPU1GND2AD143AD134AD125AD116AD107AD98AD89AD710AD611AD512AD413AD314AD215AD116AD017NMI18INTR19CLK20GND21RESET22READY23TEST'24QS1(INTA')25QS0(ALE)26S0'(DEN')27S1'(DT/R')28S2'(M/IO')29LOCK'(WR')30RQ'/GT1'(HLDA)31RQ'/GT0'(HOLD)32RD'33MN/MX'34BHE'/S735A19/S636A18/S537A17/S438A16/S339AD1540VCC
Figure 10.1.1: The pin diagram of the 8086. Pins 1–20 are on the left side and pins 21–40 on the right. Pins 24–31 have two names: the maximum-mode name outside, the minimum-mode name in parentheses.

Figure 10.1.1 shows the position of the pins on the package. What stands out at first glance is that many pins have two names separated by a slash: A17/S4, BHE'/S7, RQ'/GT0' and so on. These double names tell that the pin does two different jobs, at different times or depending on the type of system.

Definition 10.1.1

A signal that does its job when at logic level 1 (about +5 V) is an active-high signal. A signal that does its job when at logic level 0 (about 0 V) is active low. The data sheet draws an overbar above the names of active-low signals. In this course the same meaning is shown with an apostrophe at the end of the name: RD' = 0 means "a read is in progress".

Active-low signals are a habit of the TTL era. In TTL gates, pulling a line to 0 can be made stronger than pulling it to 1. Moreover, a TTL input that has come loose behaves like a 1; a broken "active-low" line therefore stays passive by itself. This is why most of the read, write, interrupt-acknowledge and select signals are active low.

Some names describe two states at once. When a name like M/IO' is read, the slash can be thought of as "or": if the pin is 1 the first meaning (M, memory) holds, if it is 0 the second (IO', input/output). MN/MX', DT/R' and BHE', which is read together with S7, follow the same pattern. The pins also have three kinds of direction. An input (I) pin only brings information to the processor, an output (O) pin only carries information out. A bidirectional (I/O) pin works in both directions.

Common mistake

Reading the DT/R' signal as "DT/R entirely active low" is wrong. The apostrophe belongs only to R: with the pin at 1 the meaning DT (data transmit) holds, at 0 the meaning R (data receive). Likewise in the M/IO' signal, M is active high and IO is active low. In the data sheet the overbar is only over the relevant part of the name.

10.1.1.2Inside the chip

In the middle of the plastic or ceramic package there is a piece of silicon a few millimetres square, the die. Bonding pads are lined up along the edges of the die. Each pad is connected to one pin of the package with a gold or aluminium wire thinner than a hair. The real job of the package is to protect this small die, to dissipate its heat and to carry its wires out to pins spaced to suit the printed circuit board.

Photograph of the 8086 die with the ALU, registers, queue, microcode, bus control and AD pads marked.
Figure 10.1.2: Die photograph of the 8086 (Ken Shirriff, righto.com). The address/data pads are on the left edge, the 16-bit registers, the ALU and the queue registers on the left, and the microcode ROM at the bottom right.

Figure 10.1.2 shows an 8086 die with its functional blocks marked. The die has about 29,000 transistors; the process is 3 µm. The pads on the left edge are the lines going to the AD pins. The registers, the ALU and the registers of the prefetch queue are close to these pads, because these blocks are the parts that exchange data with the bus most often. The large regular area at the bottom right is the microcode ROM: the internal memory that holds the steps of the complex instructions. The bus control logic generates the timing of the signals on the pins.

The die photograph shows one thing clearly: there is no memory inside the processor. Apart from the registers, all programs and data are in chips outside. Every memory access of the processor has to pass through the pins. The number and timing of the pins therefore directly limit the processor's speed.

10.1.1.3Why complicated pins?

A microprocessor is connected to memory and I/O devices through an address bus, a data bus and a control bus. How many pins would the 8086 need if every signal had its own pin? A rough count goes like this:

  • The address bus is 20 lines: A0–A19. 220 = 1 MB of memory is addressed.
  • The data bus is 16 lines: D0–D15.
  • Control, status and interrupt signals are about 20 lines: read, write, memory/I/O select, ready, interrupt request, bus request, status information.
  • Power and clock are 4 lines: VCC, two GNDs and CLK.

The total exceeds 60. In the late 1970s 64-pin packages were expensive, took up a lot of room on the board and caused trouble in production. Intel chose to stay with the 40-pin package familiar from the 8080 and 8085. The only way to close the gap was to make some pins do more than one job.

needed ≈ 60address 20data 16control ~20power/clock 4pin = 4040-pin DIPmultiplexing
Figure 10.1.3: The number of signals needed with separate pins is about 60; the package has 40 pins. The gap is closed by multiplexing.
Definition 10.1.2

Multiplexing is the carrying of different information by the same pins at different times. The 8086 uses time-division multiplexing: pins AD0–AD15 carry the low 16 bits of the address in the first clock cycle of a bus cycle and data in the following cycles. Pins A16–A19 carry the top 4 bits of the address in the first cycle and status information afterwards.

The pin shortage of the 8086 has a second source. The physical address produced with the segment registers is 20 bits, while the data bus is 16 bits. The low 16 bits of the address can share the data lines, but the extra 4 address bits (A16–A19) have no data lines to pair with. So that these four pins are not left idle, they carry status information (S3–S6) once the address time has passed.

Multiplexing has two costs. First, the rest of the system wants a separate, stable address bus; latch circuits that capture and hold the address are therefore added outside the processor. Second, because address and data pass in turn through the same pins, every memory access is spread over at least four clock cycles. A processor with 60 pins and separate buses could have been built with less external circuitry using the same technology. But the 40-pin package was cheap, and designers coming from 8085 systems already knew the multiplexed bus.

10.1.1.4Pin groups

The 40 pins can be divided into seven groups by function. Table 10.1.1 gives these groups with their pin numbers.

Table 10.1.1: The pin groups of the 8086.
GroupPinsDescription
PowerVCC (40), GND (1, 20)+5 V ± 10%
Clock and resetCLK (19), RESET (21), READY (22)all three come from the 8284A clock generator
Address/dataAD0–AD15 (2–16, 39)address in T1, then data
Address/statusA16/S3–A19/S6 (38–35), BHE'/S7 (34)address in T1, then status
InterruptNMI (17), INTR (18), INTA' (24, minimum mode)hardware interrupts
Common controlRD' (32), TEST' (23), MN/MX' (33)the same in both modes
Mode-dependent24–31minimum: INTA', ALE, DEN', DT/R', M/IO', WR', HLDA, HOLD; maximum: QS1, QS0, S0', S1', S2', LOCK', RQ'/GT1', RQ'/GT0'

The numbers of the address/data pins look irregular at a glance. AD15 is at pin 39, while the pins from AD14 down to AD0 run from 2 to 16. The four pins between A19/S6 and A16/S3 sit on the right edge, numbers 35–38, in reverse order. This layout comes from the order of the pads on the die. The AD pads in Figure 10.1.2 are lined up one after another on the left edge of the die. They are connected with the shortest wires to the pins on the left edge of the package.

The direction of a signal also depends on its group. AD0–AD15 are bidirectional: outputs during a write, inputs during a read. A16/S3–A19/S6 and BHE'/S7 are outputs only, because no external device drives these pins. CLK, RESET, READY, NMI, INTR, TEST' and MN/MX' are inputs only. RD', ALE, DEN', DT/R', M/IO', WR', INTA' and HLDA are outputs; HOLD is an input. RQ'/GT0' and RQ'/GT1' in maximum mode, however, carry out a two-way handshake on a single pin.

Table 10.1.2: The 40 pins of the 8086: number, name, direction and short function (minimum / maximum mode for 24–31).
PinNameDir.Function
1, 20GND—ground
2–16AD14–AD0I/Oaddress (T1) / data (T2–T4)
17NMIInon-maskable interrupt, rising edge
18INTRIinterrupt request, active-high level
19CLKIclock, 33% duty cycle
21RESETIreset, active high
22READYImemory/I/O ready, active high
23TEST'Iinput tested by the WAIT instruction
24INTA' / QS1Ointerrupt acknowledge / queue status
25ALE / QS0Oaddress latch enable / queue status
26DEN' / S0'Odata enable / status
27DT/R' / S1'Odata transmit/receive / status
28M/IO' / S2'Omemory or I/O / status
29WR' / LOCK'Owrite / bus lock
30HLDA / RQ'/GT1'O / I/Ohold acknowledge / bus request-grant
31HOLD / RQ'/GT0'I / I/Ohold request / bus request-grant
32RD'Oread
33MN/MX'Imode select
34BHE'/S7Obus high enable / spare status bit
35–38A19/S6–A16/S3Oaddress (T1) / status (T2–T4)
39AD15I/Oaddress (T1) / data (T2–T4)
40VCC—+5 V

Table 10.1.2 collects all 40 pins in one list and can be used as a reference table when reading circuit diagrams. There is no need to memorize pin numbers. What matters is knowing which group each pin is in and what it carries at what moment.

10.1.1.5Minimum and maximum mode

The second remedy for the pin shortage is to change the meaning of the eight pins numbered 24–31 according to the type of system. In a small system there is a single processor, and it can generate control signals such as read, write and address latch enable by itself. In a large system, however, other chips such as the 8087 floating-point coprocessor or the 8089 I/O processor share the same bus. In that case the control signals are generated by a separate chip, the 8288 bus controller. The pins freed on the 8086 are given to the new signals needed for the multiprocessor arrangement.

Definition 10.1.3

If the MN/MX' pin (pin 33) is connected to VCC, the 8086 works in minimum mode. This is a small single-processor system; pins 24–31 generate the control signals (INTA', ALE, DEN', DT/R', M/IO', WR', HLDA, HOLD) directly. If MN/MX' is connected to ground, it works in maximum mode. The same pins turn into the status code, the queue status and the bus-sharing signals: QS1, QS0, S0'–S2', LOCK', RQ'/GT1', RQ'/GT0'. The control signals are generated by the 8288.

The mode is chosen by hardware. The MN/MX' pin is permanently wired to the supply or to ground on the board and does not change while the processor runs. No instruction can change the mode; from the software's point of view there is no difference between the two modes. The same program gives the same result in both systems.

Table 10.1.3: The eight pins whose meaning changes with the mode.
PinMinimum mode (MN/MX' = 1)Maximum mode (MN/MX' = 0)
24INTA'QS1
25ALEQS0
26DEN'S0'
27DT/R'S1'
28M/IO'S2'
29WR'LOCK'
30HLDARQ'/GT1'
31HOLDRQ'/GT0'

The pairing in Table 10.1.3 is not random. Pin 28 carries, in minimum mode, the M/IO' signal that separates memory from I/O; in maximum mode it carries the status bit S2', which makes the same distinction (1 memory, 0 I/O). DT/R' on pin 27 gives the data direction, and S1' helps separate reads from writes. The 8288 in maximum mode thus receives the information of the minimum-mode signals in coded form and regenerates them. The maximum-mode counterpart of the HOLD/HLDA pair on pins 30–31 is again the RQ'/GT pins, which also hand over the bus.

Example 10.1.1

A designer is preparing a board to which an 8087 coprocessor will be added. Where should MN/MX' be connected, and which signals that it used in minimum mode can it no longer take from the 8086?

  1. The 8087 watches the 8086's queue on the QS1 and QS0 pins and requests the bus with the RQ'/GT pins. These pins exist only in maximum mode; MN/MX' is connected to ground.
  2. Because pins 24–31 change in maximum mode, the signals INTA', ALE, DEN', DT/R', M/IO', WR', HLDA and HOLD cannot be taken from the 8086.
  3. The 8288 does their job: from the S2'–S0' code it generates the signals MRDC', MWTC', IORC', IOWC', INTA', ALE, DEN and DT/R'. RQ'/GT0' and RQ'/GT1' are used in place of HOLD/HLDA.

The RD' pin (32) is on the 8086 in both modes; but in maximum mode memory and I/O reads are usually done with MRDC' and IORC', which the 8288 generates.

10.1.2Address and data pins

In a memory access the processor has two things to say: which address and which data. The 8086 sends these two pieces of information in turn on the same pins. This section first describes the job of the address/data and address/status pins over time, then how the multiplexing is undone outside. It then shows, with a code trace, how the 16-bit data bus is divided into two byte banks and why a word at an odd address takes two bus cycles.

10.1.2.1AD0–AD15 and A16/S3–A19/S6

The AD0–AD15 pins carry the low 16 bits of the address and the 16-bit data. In the first clock cycle of a bus cycle (T1) the pins hold the address; at this moment they are called A0–A15. In the following cycles (T2, T3, T4 and the wait cycles, if any) the same pins carry data; then they are called D0–D15. In a byte access only one half of the data lines is used: D0–D7 or D8–D15. The pins are bidirectional. In a write the processor drives the data out; in a read the external device drives the data in. When needed the processor can release the drivers of these pins entirely; this is called the float, or high-impedance (tri-state), state.

Definition 10.1.4

A tri-state output is an output that can take a third state in addition to the levels 0 and 1: high impedance. In this state the output drives the line neither to 0 nor to 1; electrically it is as if disconnected from the line, and another driver can drive the line. Only one driver may be active on a line at a time.

The A16/S3–A19/S6 pins carry the top 4 bits of the address. In a memory access these pins hold A16–A19 during T1. From T2 on, the same pins switch to the status bits S3–S6. In an I/O access the address is only 16 bits; the lines A16–A19 are therefore 0 in T1. S3 and S4 show which segment register is used in the access, and S5 the current value of the interrupt flag IF; S6 is always 0. The status bits are treated in detail in their own subsection.

T1T2T3T4AD15–AD0A15–A0data D15–D0A19/S6–A16/S3A19–A16status S6–S3
Figure 10.1.4: The AD15–AD0 pins carry the address in T1 and data in T2–T4. The A19/S6–A16/S3 pins carry the top four bits of the address in T1 and the status bits afterwards.

BHE'/S7 (pin 34) is close to this group. During T1 it works as BHE' (bus high enable) and tells that the upper half of the data bus (D8–D15) will be used in this cycle. During T2–T4 it turns back into the status bit S7; on the 8086, S7 is an unused spare bit. Figure 10.1.4 summarizes this time sharing: the meaning of a pin depends on the clock cycle in which it is looked at.

Common mistake

The idea that "the memory reads the address from the AD pins throughout the cycle" is wrong. The address stays on the AD pins only during T1. In T2 the pins switch to data or are floated. The memory chip, however, has to see the address during T2–T4 too. For this reason the address is taken at the end of T1 into an external latch circuit. The memory reads the address from the output of that latch.

10.1.2.2Demultiplexing: ALE and the address latch

The rest of the system, that is, memory chips, address decoders and I/O devices, wants a separate, stable address bus and a separate data bus. Separating these two buses from the multiplexed bus of the 8086 is called demultiplexing. Two kinds of circuit are used for the job: the address latch, which captures and holds the address, and the transceiver, which strengthens the data lines and sets their direction. The processor tells the latch when to capture the address with the ALE (address latch enable, pin 25) signal.

Definition 10.1.5

A latch is a memory circuit that passes the value at its input to its output while an enable input is 1 and holds the last value when the enable falls to 0. While the enable is 1 the latch is "transparent"; on the falling edge it captures the value. In 8086 systems the 8-bit 8282 or 74LS373 latches are used; ALE is connected to the enable input (STB or LE).

8086AD0–AD15ALE · DEN' · DT/R'ADAddress latch8282 / 74LS373Transceiver8286 / 74LS245A0–A15(stable address)D0–D15(system data bus)ALE → STBDEN' → OE', DT/R' → T (direction)T1: ALE = 1 → address latched8086AD0–AD15ALE · DEN' · DT/R'ADAddress latch8282 / 74LS373Transceiver8286 / 74LS245A0–A15(stable address)D0–D15(system data bus)ALE → STBDEN' → OE', DT/R' → T (direction)T2–T4: DEN' = 0 → data passes
Figure 10.1.5: Demultiplexing. Top, T1: the 8086 puts the address on the AD pins and makes ALE 1; as ALE falls, the latch captures the address. Bottom, T2–T4: the same pins carry data; DEN' = 0 turns on the transceiver and DT/R' selects the direction.

Figure 10.1.5 shows the two phases of a cycle side by side. In T1 the 8086 puts the address on the AD pins and makes ALE 1 for a short pulse. While ALE is 1 the latch is transparent; the address on the pins passes to the latch's output. When ALE falls to 0, the latch captures the current value and holds it at its output until the end of the cycle. After T2 the AD pins carry data, but the address at the latch's output does not change. Memory and I/O devices see the address at the latch's output and the data at the far end of the transceiver.

Why ALE uses the falling edge can be understood from the timing values in the data sheet. On a 5 MHz 8086, ALE becomes 1 at most 80 ns after the clock edge at the start of T1 (TCLLH). The address becomes valid at most 110 ns after (TCLAV). So when ALE rises, the address may not yet be stable. The data sheet, however, guarantees two things. The address is valid at least TAVAL = TCLCH − 60 ns before ALE falls. After ALE falls it also stays on the pins for at least TLLAX = TCHCL − 10 ns. A transparent latch is therefore the right choice: while ALE is 1 the output follows the address, and as ALE falls the settled address is captured.

Example 10.1.2

On a 5 MHz 8086 (TCLCL = 200 ns) the low time of the clock is at least TCLCH = 118 ns and the high time at least TCHCL = 69 ns. How long before ALE falls is the address valid at the least, and how long does it stay on the pins after ALE falls at the least?

  1. TAVAL = TCLCH − 60 = 118 − 60 = 58 ns: the address at the latch input is stable at least 58 ns before the moment of capture.
  2. TLLAX = TCHCL − 10 = 69 − 10 = 59 ns: the address stays on the pins at least 59 ns after the moment of capture.
  3. According to the 74LS373 data sheet, the data at the input must be set up at least 5 ns before LE falls and held at least 20 ns after it falls. Since 58 ns ≥ 5 ns and 59 ns ≥ 20 ns, both conditions are met with a wide margin.

As long as the latch's setup and hold times are smaller than the guarantees given by the 8086, the captured address is correct.

8086AD0–AD15ALE · DEN' · DT/R'ADAddress latch8282 / 74LS373Transceiver8286 / 74LS245A0–A15(stable address)D0–D15(system data bus)ALE → STBDEN' → OE', DT/R' → T (direction)The latch keeps the address after ALE falls
Figure 10.1.6: Top: the multiplexed bus and the two demultiplexing circuits, the address latch (8282 / 74LS373) and the transceiver (8286 / 74LS245). Bottom: the rest of the cycle: the latch keeps holding the address after ALE falls.

For a 20-bit address three 8-bit latches are needed. One captures A0–A7, one A8–A15. The third holds A16–A19 and the BHE' signal: these five signals also switch to status information after T1, so they must be captured too. The unused inputs of the third latch are left idle. Figure 10.1.6 gives a simplified view of this arrangement.

The 8282 and the 74LS373 do the same job: both are 8-bit transparent latches with tri-state outputs. The 74LS373 has two control inputs: LE (latch enable) and OE' (output enable). ALE is connected to LE, and OE' is kept constantly at 0 so that the latch's output always drives the address bus. When the bus is handed to another master, the latch outputs can also be floated by making OE' 1. The 8283 is the version of the 8282 whose outputs are inverted.

Common mistake

Using, instead of an address latch, a D flip-flop chip that captures on the rising edge (for example a 74LS374) and connecting ALE directly to its clock input is a mistake. The flip-flop captures the address on the rising edge of ALE. At that moment the address may not yet be valid: ALE rises at 80 ns at the latest, the address settles at 110 ns at the latest. If a flip-flop is to be used, the inverse of ALE is given as the clock; the capture then moves to the falling edge of ALE.

10.1.2.3A buffered and latched system

The latches produce the address bus. For the data bus a transceiver is used. A transceiver is a bidirectional buffer: a combination of a transmitter and a receiver in one package. The 8286, and the 74LS245 often used in its place, are 8-bit transceivers; two are needed for the 16-bit data bus. A transceiver has two control inputs. The direction input (T on the 8286, DIR on the 74LS245) selects which side the data flows from and to. When the enable input (OE' or G') is 1, it floats both sides and isolates the lines from each other.

8086MN/MX' = 1A16–A19, BHE'8282 latchA16–A19, BHE'AD8–AD158282 latchA8–A15AD0–AD78282 latchA0–A7Address bus (20 bits)AD8–AD158286 XCVRD8–D15AD0–AD78286 XCVRD0–D7Data bus (16 bits)ALE → STBDEN' → OE', DT/R' → T
Figure 10.1.7: A buffered and latched minimum-mode system: three 8282 latches produce the 20-bit address bus and the BHE' signal, and two 8286 transceivers produce the 16-bit data bus. ALE controls the latches, DEN' and DT/R' the transceivers.

Figure 10.1.7 shows a complete minimum-mode bus interface. The 8086's DT/R' output is connected to the transceiver's direction input and its DEN' output to the enable input. With DT/R' = 1 data flows from the processor to memory, with 0 from memory to the processor. DEN' is 0 only while data is being transferred; it stays 1 in T1 so that the address on the AD pins does not leak onto the data bus. These two signals are treated, with their timing, in the subsection on the control pins.

The second job of the buffers is to provide drive strength. An output pin of the 8086 can sink at most 2.5 mA at the low level, and the data sheet limits the output load to 20–100 pF. The current that a 74LS input supplies at the low level is about 0.4 mA. A single pin of the 8086 can therefore safely drive only a few LS inputs. On a large board with dozens of memory chips every bus line goes to many inputs, and the capacitance of long traces is added. Latches and transceivers carry this load in place of the processor. This is why in large systems the address, data and control buses are all buffered.

Example 10.1.3

One AD pin of the 8086 can sink 2.5 mA at the low level. At most how many 74LS inputs, each requiring 0.4 mA at the low level, can it drive directly? How many inputs can a 74LS245 output drive if it can sink 24 mA at the low level?

  1. The 8086 pin: 2.5 / 0.4 = 6.25 → at most 6 inputs. In practice fewer are used, for line capacitance and noise margin.
  2. The 74LS245 output: 24 / 0.4 = 60 inputs.

The transceiver raises the current-driving capacity about tenfold. As the memory board grows, this difference becomes decisive.

10.1.2.4BHE' and A0: the memory banks

The data bus of the 8086 is 16 bits wide, but memory is addressed at byte level. Every address points to one byte. So that the processor can transfer both a single byte and a word made of two consecutive bytes in one cycle, the 1 MB memory is physically divided into two halves. Each half is called a memory bank.

Definition 10.1.6

The low bank (even bank) holds the bytes at even addresses and is connected to the data lines D0–D7. The high bank (odd bank) holds the bytes at odd addresses and is connected to D8–D15. Each bank is 512 KB and is addressed in parallel by the address lines A1–A19. A0 = 0 selects the low bank and BHE' = 0 the high bank.

8086High bankodd addresses (1, 3, 5 …)Low bankeven addresses (0, 2, 4 …)D8–D15D0–D7A1–A19BHE' = 0A0 = 0512 KB × 8512 KB × 8
Figure 10.1.8: The even and odd memory banks. The low bank is connected to D7–D0 and selected with A0 = 0; the high bank is connected to D15–D8 and selected with BHE' = 0. Both banks are addressed with A19–A1.

In Figure 10.1.8 the two banks share the same address lines. A1–A19 go to the banks, not A0; because consecutive bytes within one bank are at addresses that increase by 2. For example, bytes 0, 1, 2 of the low bank correspond to addresses 00000h, 00002h, 00004h, and those of the high bank to 00001h, 00003h, 00005h. Two addresses with the same A19–A1, that is 2k and 2k + 1, are in the same row of the two banks and can be read together in one cycle.

Table 10.1.4: Bank selection with BHE' and A0.
BHE'A0TransferLines used
00whole word (even address)D15–D0
01high byte (odd address)D15–D8
10low byte (even address)D7–D0
11no transfer—

Table 10.1.4 gives the four cases. When a byte at an even address is written, only the write enable of the low bank must be opened; the neighbouring byte in the high bank must not be corrupted. The bank selection is therefore combined with the memory write signal: the low bank's write input is derived from WR' and A0, the high bank's from WR' and BHE'. In a read, there is no harm in reading both banks together; the processor takes only the half it needs. Even so, in most designs bank selection is applied in reads too.

For a word starting at an odd address, the low byte is in the high bank and the high byte is in the low bank of the next row. Because the two bytes are in different rows, they cannot be read together in one cycle. The 8086 splits this into two bus cycles by itself: first it transfers the byte at the odd address over D8–D15, then the byte at the next even address over D0–D7. This splitting is invisible to the programmer; the instruction gives the right result, it merely takes longer. The data sheet notes that this penalty applies only to word operands, not to instruction fetch: instructions are always fetched into the queue as words starting at an even address.

Common mistake

The idea that "a byte at an odd address also takes two cycles" is wrong. A byte access is a single cycle at whatever address: a byte at an even address passes over D0–D7, a byte at an odd address over D8–D15. Two cycles are needed only for a word access that starts at an odd address. To align data on even addresses the assembler's EVEN directive is used.

10.1.2.5Code trace: aligned and misaligned access

The program below writes the same word once to an even and once to an odd address; then it reads a byte and a word. Tracing how many bus cycles are made in every data access, the values of BHE' and A0, and over which lines the data passes makes the bank layout concrete. The contents of addresses 20100h–20102h are assumed unknown (??) at the start.

mov ax, 2000h
mov ds, ax
mov ax, 1234h
mov [0100h], ax    ; even address
mov ax, 0ABCDh
mov [0101h], ax    ; odd address
mov al, [0100h]    ; byte
mov bx, [0101h]    ; odd address

The first two instructions load 2000h into DS; the data segment starts at physical address 20000h. These two instructions change only registers. On the bus only the cycles that fetch the instruction bytes are seen; there are no data cycles. mov ax, 1234h puts 1234h in AX: AH = 12h, AL = 34h.

mov [0100h], ax computes the physical address 20000h + 0100h = 20100h. The address is even. The 8086 puts BHE' = 0 and A0 = 0 in T1; both banks are selected at once. The word is written in a single cycle: the 34h in AL goes over D7–D0 to the even address (20100h), the 12h in AH over D15–D8 to the odd address (20101h). The little-endian layout fits the bank layout naturally: the low byte is written to the low address and the low bank.

mov ax, 0ABCDh makes AX ABCDh. The 0 at the start of the number keeps the assembler from taking ABCDh for a label name. mov [0101h], ax writes to the odd address 20101h. The 8086 splits this access into two cycles. In the first cycle the address is 20101h: with BHE' = 0, A0 = 1 only the high bank is selected, and the CDh in AL is written to 20101h over D15–D8. In the second cycle the address is 20102h: with BHE' = 1, A0 = 0 only the low bank is selected, and the ABh in AH is written to 20102h over D7–D0. This write overwrites the old 12h at 20101h with CDh.

mov al, [0100h] reads a byte from the even address: BHE' = 1, A0 = 0, the data comes over D7–D0. AL = 34h; AH does not change, so AX = AB34h. The last instruction, mov bx, [0101h], is again a misaligned word read. The first cycle fetches the CDh at 20101h over D15–D8. The processor puts this byte in the low half of the word, BL. The second cycle fetches the ABh at 20102h over D7–D0; this byte goes to BH. The result is BX = ABCDh.

Table 10.1.5: The data bus cycles of the aligned and misaligned access program.
InstructionCyclePABHE'A0D15–D8D7–D0RD'/WR'Result
mov [0100h],ax1/1 write20100h0012h34h1/0[20100h] = 34h, [20101h] = 12h
mov [0101h],ax1/2 write20101h01CDh—1/0[20101h] = CDh
2/2 write20102h10—ABh1/0[20102h] = ABh
mov al,[0100h]1/1 read20100h10—34h0/1AX = AB34h
mov bx,[0101h]1/2 read20101h01CDh—0/1BL = CDh
2/2 read20102h10—ABh0/1BX = ABCDh

Table 10.1.5 shows that the four data instructions make a total of 6 data bus cycles: 1 + 2 + 1 + 2. At the end of the program AX = AB34h and BX = ABCDh; in memory 20100h = 34h, 20101h = CDh, 20102h = ABh. When the program is run in emu8086, the register and memory values come out the same. The emulator does not show banks and cycles; the number of cycles and the BHE'/A0 values follow only from whether the physical address is odd or even.

The lengths of the instruction codes also give information. mov [0100h], ax is 3 bytes, A3 00 01; the short accumulator form is used for AX. mov bx, [0101h] is 4 bytes, 8B 1E 01 01. These bytes are brought into the queue by instruction-fetch cycles, in addition to the data cycles.

Example 10.1.4

A 5 MHz 8086 reads an array of 1000 words from memory with no wait states. How long do the data cycles take if the array starts at an even address and if it starts at an odd address?

  1. One bus cycle is 4 × 200 ns = 800 ns.
  2. In an array that starts at an even address every word is a single cycle: 1000 × 800 ns = 800 µs.
  3. In an array that starts at an odd address every word takes two cycles: 2000 × 800 ns = 1600 µs.

The difference in alignment alone doubles the data access time. Keeping the stack at an even address is important for the same reason: every PUSH and POP in interrupts and procedure calls is a word access.

10.1.3Bus cycles

To understand in which order the address, data and control signals appear on the pins, time must be divided into clock cycles. This section defines the T states of a bus cycle and then traces the write and read cycles cycle by cycle. It gives all the control signals of the read cycle together with the timing values from the data sheet. Finally it describes how a slow memory requests a wait state through the READY signal, and how to compute the number of wait states a memory needs.

10.1.3.1The bus cycle and the T states

Definition 10.1.7

Every exchange of data between the processor and memory or I/O is a bus cycle. On the 8086 a bus cycle lasts at least four clock cycles. These cycles are called the T states: T1, T2, T3, T4. For a slow device, wait states (Tw) can be inserted between T3 and T4. The cycles in which the processor does not use the bus at all are idle states (Ti).

Every T state begins on one falling edge of the clock and ends on the next. The meaning of the pins changes with the T state. In T1 the AD pins hold the address, A16–A19 hold the upper bits of the address, and the ALE pulse is given. T2 is mostly preparation: in a read the direction of the bus is changed and the control signals (RD', WR') become active. The data transfer takes place in T3 and T4. T4 is the closing of the cycle: the control signals return to passive and the bus is prepared for the next cycle.

CLKT1addressT2controlT3dataTwwaitT4finishTiidle
Figure 10.1.9: Timeline of a bus cycle: T1 address, T2 control, T3 data, Tw wait if needed, T4 finish. When the bus is not in use the processor is in idle (Ti) cycles.

Once the clock frequency is known, the duration of a bus cycle is computed directly. At a 5 MHz clock one cycle is T = 1 / 5 MHz = 200 ns; a bus cycle without wait states takes 4 × 200 = 800 ns. At most 1 / 800 ns = 1.25 million bus cycles can be made in a second. Since every cycle carries at most 2 bytes, the highest bandwidth of the bus is about 2.5 MB/s.

Example 10.1.5

Find the duration of a bus cycle without wait states and the highest bus bandwidth for the 8086 (5 MHz), the 8086-2 (8 MHz) and the 8086-1 (10 MHz).

  1. 5 MHz: T = 200 ns, cycle 800 ns, 1.25 × 106 cycles/s × 2 bytes = 2.5 MB/s.
  2. 8 MHz: T = 125 ns, cycle 500 ns, 2 × 106 cycles/s × 2 bytes = 4 MB/s.
  3. 10 MHz: T = 100 ns, cycle 400 ns, 2.5 × 106 cycles/s × 2 bytes = 5 MB/s.

These values are upper limits. In reality part of the bus goes to instruction fetch, misaligned words take two cycles and slow memories add wait states.

Idle states arise at moments when the processor does not use the bus. For example, when the prefetch queue is full and the instruction being executed asks for no memory, the BIU has nothing to do; the bus waits in Ti cycles. The data sheet notes that these cycles are used for internal work. In Ti cycles the control signals stay passive, and the bus can easily be handed to another master by a HOLD request.

10.1.3.2The write bus cycle

A write cycle consists of four T states. Figure 10.1.10 shows a simplified timeline of a memory write.

T1T2T3T4One bus cycleCLKvalid address (A16–A19, latched A0–A15)Addressaddressdata written to memoryAD15–AD0WR'T1T2T3T4One bus cycleCLKvalid address (A16–A19, latched A0–A15)Addressaddressdata written to memoryAD15–AD0WR'
Figure 10.1.10: The write bus cycle. Top, T1: the target address is on the AD and A pins and is captured by the latches with ALE. Bottom, T2: the AD pins carry the data to be written and WR' = 0.
  1. T1: The processor puts the target address on the AD0–AD15 and A16–A19 pins. The ALE pulse captures the address in the external latches. M/IO' became valid in T4 of the previous cycle; it is 1 for a memory write and 0 for an I/O write.
  2. T2: The AD pins switch from address to data: the processor drives the data to be written at once. The WR' signal becomes 0 at the start of T2. The A16–A19 pins switch to the status bits (S3–S6).
  3. T3: The data and WR' stay stable. The memory prepares to capture the data. If the device is not ready it keeps READY at 0; in that case a Tw is added after T3.
  4. T4: WR' returns to 1. Most memories write the data on the rising edge of WR'. The data stays on the pins until the middle of T4; thus on the rising edge the memory sees stable data.

In a write cycle the address is in T1 and the data is on the same pins from T2 to T4, with no gap in between. The reason is that the source of the data is the processor itself: the drivers that drove the address go on to drive the data in the next cycle. The direction of the bus does not change.

The data sheet gives the width of the WR' pulse as TWLWH ≥ 2TCLCL − 60. At 5 MHz that is 2 × 200 − 60 = 340 ns. The shortest write pulse a memory chip asks for must be shorter than this; if not, the pulse is lengthened by adding wait states. Every Tw extends the time WR' stays 0 by one more cycle.

10.1.3.3The read bus cycle

A read cycle also consists of four T states. The important difference is that there is a gap between the address and the data on the AD pins. Figure 10.1.11 shows this gap.

T1T2T3T4One bus cycleCLKvalid addressAddressaddressdata readAD15–AD0RD'T1T2T3T4One bus cycleCLKvalid addressAddressaddressdata readAD15–AD0RD'
Figure 10.1.11: The read bus cycle. Top, T3: the memory puts the requested data on the data bus. Bottom, T4: the 8086 samples the data at the start of T4, RD' returns to 1 and the memory releases the bus. Between the address and the data the AD pins float in T2.
  1. T1: As in a write, the address to be read is put on the pins and captured with ALE.
  2. T2: The 8086 makes the output drivers of the AD pins tri-state; the pins float. From this moment on the memory may drive the bus. The RD' signal becomes 0.
  3. T3: When the memory or I/O device sees RD' = 0, it turns on its outputs and puts the requested data on the data bus.
  4. T4: At the start of T4, that is, on the falling clock edge that ends T3, the 8086 reads the data from the pins. RD' returns to 1 and the memory releases the bus by turning off its outputs.
Definition 10.1.8

Bus turnaround is the moment at which the driver of a bidirectional line changes. In a read cycle the AD lines are driven by the processor in T1 and by the memory in T3–T4. The float state in T2 is for this turnaround: if the memory started driving the data before the processor stopped driving the address, the two outputs would collide on the same line.

A collision does not mean just wrong data. If one output drives a line to 1 and the other to 0, a current close to a short circuit flows between the two drivers; this is called bus contention. Continuous contention heats the chips and damages them over time. This is why the data sheet gives two separate guarantees. The AD pins float at most TCLAZ = 80 ns after the clock edge at the start of T2. The RD' signal also stays 1 in T2 until the local bus floats. The memory turns on its output only after RD' = 0. The memory thus safely takes over the line that the processor has released.

Common mistake

The assumption that "in a read the data is ready in T2 as in a write" is wrong. In a read the data comes from an external device, and the device turns on its output only after it sees RD' = 0. RD' falls within T2, and the device's access delay is added; the data goes onto the bus within T3 at the earliest and is sampled at the start of T4. In a write, since the processor drives the data, it is on the pins from the start of T2.

10.1.3.4Bus timing for a read

The simplified timelines show only the address, the data and the read signal. In a memory read in minimum mode six more control signals play a part: M/IO', ALE, DT/R', RD', DEN' and READY. Figure 10.1.12 gives them all on the same clock axis.

T1T2T3T4800 ns (5 MHz)CLKA19–A16S6–S3A19–16/S6–3A15–A0data inAD15–AD0M/IO' = 1 (memory)M/IO'ALEDT/R'RD'DEN'READYREADY = 1: memory ready → no wait
Figure 10.1.12: All the signals in a memory read cycle in minimum mode (5 MHz, 800 ns). M/IO' is 1 throughout the cycle, ALE pulses in T1, DT/R' is 0 throughout the cycle, RD' and DEN' are 0 from T2 to T4; because READY = 1 there is no wait state.

Let us read the signals cycle by cycle:

  • T1: M/IO' = 1 (memory) has been valid since T4 of the previous cycle and stays through the cycle. The address is on the AD and A pins. The ALE pulse captures the address. DT/R' = 0: the transceiver is set to the "receive" direction. DEN' = 1: the transceiver is still off.
  • T2: The AD pins float; the status bits S6–S3 appear on the A19–A16 pins. RD' becomes 0. Then DEN' becomes 0 and the transceiver turns on. According to the data sheet, in a read DEN' is active from the middle of T2 to the middle of T4; in a write, from the start of T2 to the middle of T4.
  • T3: The memory puts the data on the data bus; the data passes through the transceiver and reaches the AD pins. The processor samples READY during T3. If READY = 1 the cycle goes on to T4.
  • T4: The data is sampled at the start of T4. RD', DEN' and DT/R' return to passive. M/IO' may change within T4 depending on the type of the next cycle.
Table 10.1.6: Some timing values of the 8086 (data sheet, minimum mode). TCLCL is the clock period.
SymbolMeaning8086 (5 MHz)8086-2 (8 MHz)8086-1 (10 MHz)
TCLCLclock period200–500 ns125–500 ns100–500 ns
TCLCHclock low time (minimum)118 ns68 ns53 ns
TCHCLclock high time (minimum)69 ns44 ns39 ns
TCLAVclock to address valid (maximum)110 ns60 ns50 ns
TCLAZclock to address float (maximum)80 ns50 ns40 ns
TCLRLclock to RD' falling (maximum)165 ns100 ns70 ns
TDVCLdata setup before the clock edge (minimum)30 ns20 ns5 ns
TRYHCHREADY setup before the clock edge (minimum)118 ns68 ns53 ns
TRLRHRD' pulse width (minimum)2TCLCL − 752TCLCL − 502TCLCL − 40
TWLWHWR' pulse width (minimum)2TCLCL − 602TCLCL − 402TCLCL − 35

Table 10.1.6 gives values selected from the data sheet's AC characteristics table. The naming rule of the symbols makes them easier to read: the first two letters describe the starting event, the last two the ending event. CL means "clock falls", CH "clock rises", AV "address valid", RL "RD' falls", DV "data valid". TCLAV is the longest time from the falling edge of the clock until the address becomes valid.

The upper limit of the clock period also draws attention: TCLCL can be at most 500 ns, that is, the clock cannot fall below 2 MHz. The 8086 is a dynamic design; the charges on its internal nodes are lost if they wait longer than a certain time. The clock therefore cannot be stopped or slowed down very much.

10.1.3.5READY and the wait state

The access time of a memory chip is the time from the moment it receives the address to the moment it puts the data on its output. A slow memory with a long access time cannot prepare its data by the end of T3. The 8086 solves this with the READY input.

Definition 10.1.9

READY (pin 22) is an active-high input that tells that the addressed memory or I/O device will complete the data transfer. The processor samples READY during T3. If READY = 0 it does not go on to T4; it adds a wait state (Tw) and samples READY again in Tw. It keeps adding Tw until READY becomes 1.

T1T2T3TwT4One bus cycleCLKaddressdataAD15–AD0RD'READYT1T2T3TwT4One bus cycleCLKaddressdataAD15–AD0RD'READY
Figure 10.1.13: A read cycle with a wait state. Top, T3: READY = 0 is seen, the processor adds a Tw instead of T4 and all the signals stay as they are. Bottom, T4: READY = 1 has been sampled in Tw; the data is read. The cycle takes 5 × 200 = 1000 ns.

Figure 10.1.13 shows a read with a single wait state. When a slow memory is selected, the address decoder immediately pulls READY to 0. In T3 the processor sees READY = 0 and does not go to T4; it adds a Tw. During Tw, RD', DEN', DT/R' and the address stay as they are. The memory prepares its data in this extra cycle and raises READY to 1. When READY = 1 is sampled in Tw, the next cycle is T4 and the data is read. The cycle takes five cycles instead of four, that is, 5 × 200 = 1000 ns; each wait state adds 200 ns to the cycle.

The timing of READY is tight. At 5 MHz, READY must be stable at least TRYHCH = 118 ns before the rising clock edge in T3. Since the low time of the clock is also about 133 ns, READY must in practice be ready at the start of T3. Moreover, the READY input of the 8086 is not synchronized internally: if the setup and hold times are not met, the processor may behave erratically. This is why the ready signal of the memory and I/O devices is connected not directly to the 8086 but to the RDY input of the 8284A clock generator. The 8284A synchronizes RDY with the clock and gives the 8086 a READY that obeys the rules. The data sheet notes that RDY is sampled toward the ends of T2, T3 and Tw.

Common mistake

Thinking of READY as an active-low "wait" signal is confusing. READY is active high: 1 means "I am ready, continue", 0 means "I am not ready, wait". In a system with no slow device attached READY is held at 1 constantly. A READY whose connection was forgotten and which stays at 0 puts the processor into an endless wait state at the first memory access.

10.1.3.6How many wait states are needed?

The number of wait states needed for a memory is found by comparing the time the processor allows the memory with the memory's access time. In a read the address becomes valid at most TCLAV after the clock edge at the start of T1. The data is sampled at the end of T3, on the clock edge that goes to T4, and must be ready at least TDVCL before this edge. There are three cycles between these two moments. The delays of the address latch, the address decoder and the data transceiver eat part of the time in between; let us call their sum tbuf.

The time left to the memory is written as:

tallowed = 3·T − TCLAV − TDVCL − tbuf

Every Tw extends this window by one T. With n wait states the allowed time becomes tallowed + n·T. The memory's access time taccess must not exceed this time:

taccess ≤ tallowed + n·T  ⇒  n = ⌈(taccess − tallowed) / T⌉  (n = 0 if the result is negative)

Example 10.1.6

In a 5 MHz 8086 system, T = 200 ns, TCLAV ≤ 110 ns and TDVCL ≥ 30 ns are taken from the data sheet; the sum of the latch, decoder and transceiver delays is assumed to be tbuf = 40 ns. How many wait states are needed for a memory with an access time of 700 ns?

  1. tallowed = 3 × 200 − 110 − 30 − 40 = 600 − 180 = 420 ns.
  2. n = ⌈(700 − 420) / 200⌉ = ⌈280 / 200⌉ = ⌈1.4⌉ = 2.
  3. Check: with 1 Tw the window is 420 + 200 = 620 ns; 620 < 700, not enough. With 2 Tw it is 420 + 400 = 820 ns; 820 ≥ 700, enough.
  4. The cycle time is (4 + 2) × 200 = 1200 ns.

For a memory with an access time of 400 ns, since 400 ≤ 420 no wait state is needed; the cycle stays at 800 ns.

The computation uses the ceiling function (⌈ ⌉), because wait states are added as whole cycles; adding 1.4 cycles is not possible. If a memory misses the window by even 1 ns, one more full cycle is added. A memory whose access time slightly exceeds the window therefore slows the system down by a whole cycle.

This computation examines only the "address to data" condition. In a read there is a second condition. The memory turns on its output only after RD' = 0. The output-enable time, from the fall of RD' until the data appears at the output, must also fit in the window. RD' falls at most TCLRL = 165 ns after the start of T2. The data must be ready TDVCL before the edge 2T = 400 ns after the start of T2. This second window is 400 − 165 − 30 = 205 ns; the transceiver delay is also subtracted from it. The memory's output-enable time must be shorter than this value. Every Tw lengthens this window by one T as well.

Example 10.1.7

An 8 MHz 8086-2 system uses the same 700 ns memory. The data sheet gives TCLAV ≤ 60 ns and TDVCL ≥ 20 ns; tbuf = 40 ns. How many Tw are needed, and how much of the gain of the faster clock do the wait states take back?

  1. T = 125 ns; tallowed = 3 × 125 − 60 − 20 − 40 = 375 − 120 = 255 ns.
  2. n = ⌈(700 − 255) / 125⌉ = ⌈445 / 125⌉ = ⌈3.56⌉ = 4.
  3. Check: with 3 Tw, 255 + 375 = 630 ns, not enough; with 4 Tw, 255 + 500 = 755 ns, enough.
  4. The cycle is (4 + 4) × 125 = 1000 ns.

In the 5 MHz system the same memory gave a 1200 ns cycle. Although the clock is 1.6 times faster, the memory cycle shortens only 1.2 times (from 1200 ns to 1000 ns). A slow memory makes the fast processor spend most of its gain in wait states.

10.1.4Status pins

In every bus cycle the 8086 also reports to the outside, in coded form, what it is doing. The pins that carry this information are called the status pins. In maximum mode the pins S2', S1', S0' give the type of the cycle; the 8288 bus controller decodes this code and generates the read and write commands. In both modes the A16–A19 and BHE' pins carry the status bits S3–S7 after the address time. In maximum mode QS1 and QS0 describe what is going on in the prefetch queue. This section treats the three groups in turn and traces which codes appear on each instruction of a program.

10.1.4.1S2', S1', S0'

S2', S1' and S0' are pins 28, 27 and 26 in maximum mode. Three bits give eight different codes; each code describes a type of bus cycle. The codes are valid in T4 of the previous cycle, in T1 and in T2. In T3, or in a Tw when READY = 1, the pins return to the passive code (1, 1, 1).

T4 (prev.)code (e.g. 101)T1code (e.g. 101)T2code (e.g. 101)T3passive 111T4passive 111The 8288 decodes from T4 to T2; leaving 111 in T4 announces a new cycle
Figure 10.1.14: The S2' S1' S0' status code is valid in T4 of the previous cycle, in T1 and in T2; in T3 it returns to the passive code (111). The change from the passive code to another code announces that a new cycle is starting.

The timing of the status pins makes the 8288's job easier. Between cycles the pins are in the passive code. In T4 a change from the passive code to any code tells the 8288 "a new bus cycle is starting". The 8288 decodes this code in the next T1, generates ALE and prepares the appropriate command signal. That the pins return to passive in T3 also announces that the end of the cycle is near.

Table 10.1.7: The S2' S1' S0' codes and the command signals the 8288 generates.
S2'S1'S0'Cycle type8288 command
000interrupt acknowledgeINTA'
001read I/O portIORC'
010write to I/O portIOWC', AIOWC'
011halt (HLT)none
100code access (instruction fetch)MRDC'
101memory readMRDC'
110memory writeMWTC', AMWC'
111passive (no cycle)none

Table 10.1.7 can be read by a rule. If S2' = 1 the cycle concerns memory; if S2' = 0 it is I/O or a special cycle. The pair S1' S0' means read when it is 01 and write when it is 10. This rule coincides with the minimum-mode signals: S2' shares a pin (28) with M/IO' of minimum mode, and S1' shares a pin (27) with DT/R'. The pairs 00 and 11 are special cases: for memory 00 describes instruction fetch, on the I/O side 00 describes interrupt acknowledge, and 11 describes halt.

The status pins are active low. The code 111, in which all bits are 1, therefore means "no cycle". If a line breaks or floats it is pulled to 1 and the 8288 does not generate commands for nothing.

Common mistake

It is wrong to think that the codes 100 (code access) and 101 (memory read) produce different commands. The 8288 generates MRDC' for both; for memory they are the same read. The distinction is for other chips that watch the bus. For example, debugging hardware may record only instruction fetches. In maximum mode a system can also build separate memories for code and data.

10.1.4.2S3–S6 and BHE'/S7

The pins A16/S3, A17/S4, A18/S5 and A19/S6 carry the top four bits of the address in T1 and switch to status bits during T2–T4. These bits exist in both modes.

Table 10.1.8: The segment shown by the bits S4 and S3.
S4 (A17)S3 (A16)Segment used
00ES (extra segment)
01SS (stack)
10CS or no segment (I/O, interrupt vector)
11DS (data)

Table 10.1.8 gives how the bits S4 and S3 show which segment register was used to compute the physical address in that cycle. Instruction fetch is always done with CS and gives the code 10. In an I/O access and in reading an interrupt vector the address does not come from a segment register; they also use the code 10. A segment override changes the code: the read of the instruction MOV AL, ES:[BX] gives 00 (ES).

The other status bits are:

  • S5 (A18): the current value of the interrupt flag IF. It is updated at the start of every clock cycle. An external monitoring circuit sees from this bit whether the processor is open to interrupts.
  • S6 (A19): always 0 on the 8086; it shows that the bus is being used by the 8086.
  • S7 (BHE'): the spare status bit seen on the BHE' pin in T2–T4; it has no meaning on the 8086.

The bits S3 and S4 offer an interesting system possibility. These bits are not latched with ALE, but they stay on the pins from T2 on and an external circuit can use them as additional address lines. A separate 1 MB memory could thus be attached to every segment: code, data, stack and extra segment go to separate memory banks. The total address space would in theory rise to 4 MB. This arrangement did not become widespread in practice, but it shows well the function of the status bits.

Example 10.1.8

What are S4 S3 in the data cycles of the following accesses?

  1. MOV AX, [SI+2]: no base register, index SI; default segment DS → 11.
  2. MOV AX, [BP+SI]: BP is in the address; default segment SS → 01.
  3. STOSB: the string destination is always ES:DI → 00.
  4. Writing the return address to the stack with CALL: SS → 01.
  5. OUT DX, AL: I/O, no segment → 10.

The segment rule follows from how the instruction is written. The status bits are the reflection of this rule in the hardware.

10.1.4.3Code trace: instructions and status codes

The program below consists of seven instructions that produce various types of bus cycle. Let us trace what is seen on the S2' S1' S0' and S4 S3 pins in every data cycle of an 8086 running in maximum mode, and which command the 8288 generates. It is assumed that the word 1234h is at address DS:0200h in memory and the value 5Ah is at port number 60h. The program is in .COM form; CS = DS = SS = 0700h and initially SP = FFFEh, AX = 0000h.

org 100h
mov bx, 0200h
mov ax, [bx]      ; memory read
mov [bx+2], ax    ; memory write
in al, 60h        ; I/O read
out 61h, al       ; I/O write
push ax           ; write to the stack
hlt               ; halt

mov bx, 0200h works only with a register. On the bus only instruction-fetch cycles are seen for this instruction: S2' S1' S0' = 100, S4 S3 = 10 (CS). For this code the 8288 generates MRDC'; the memory supplies the instruction bytes that CS:IP points to.

mov ax, [bx] is a memory read: code 101. The address is DS:0200h; since DS = 0700h the physical address is 07000h + 0200h = 07200h. Because the address is even, the word comes in a single cycle. Since the data segment is used, S4 S3 = 11. The 8288 generates MRDC' and AX = 1234h.

8086 status pinsS2'1S1'0S0'1S41S31→ DS8288 bus controllerMRDC'memory readaddr: DS:0200hAX = 1234h · SP = FFFEh8086 status pinsS2'1S1'1S0'0S41S31→ DS8288 bus controllerMWTC', AMWC'memory writeaddr: DS:0202hAX = 1234h · SP = FFFEh
Figure 10.1.15: Left, mov ax, [bx]: memory read, S2' S1' S0' = 101, S4 S3 = 11 (DS), the 8288 generates MRDC'. Right, mov [bx+2], ax: memory write, 110, the segment is again DS, the 8288 generates MWTC' and AMWC'.

mov [bx+2], ax writes to memory: code 110. The effective address is 0202h and the physical address 07202h; again an even address and a single cycle. The 8288 generates MWTC' (the memory write command). It also gives the AMWC' (advanced memory write) output, which starts one clock earlier. Since the segment is DS, S4 S3 = 11 stays. 34h is written to 07202h and 12h to 07203h.

in al, 60h is an I/O read: code 001, and the 8288 generates IORC'. Because the I/O address does not come from a segment register, S4 S3 = 10; the lines A19–A16 are 0 in T1. The port supplies 5Ah and AL = 5Ah, AX = 125Ah. Because the port number 60h is even, the byte comes over D7–D0.

8086 status pinsS2'0S1'1S0'0S41S30→ CS or none8288 bus controllerIOWC', AIOWC'I/O writeaddr: port 61hAX = 125Ah · SP = FFFEh8086 status pinsS2'1S1'1S0'0S40S31→ SS8288 bus controllerMWTC', AMWC'memory writeaddr: SS:FFFChAX = 125Ah · SP = FFFCh
Figure 10.1.16: Left, out 61h, al: I/O write, 010, the 8288 generates IOWC'; since S2' = 0 memory takes no part in this cycle. Right, push ax: again a memory write (110), but the stack segment is used: S4 S3 = 01 (SS).

out 61h, al is an I/O write: code 010, and the 8288 generates IOWC' and AIOWC'. Because S2' = 0, the memory control logic takes no part in this cycle at all. Since port 61h is an odd address, the 5Ah in AL goes out over D15–D8 and BHE' = 0.

push ax is also a memory write (110), but the address comes from the stack segment. PUSH first decreases SP by 2: SP = FFFCh. The word is written to SS:FFFCh, that is, to physical address 07000h + FFFCh = 16FFCh. S4 S3 = 01 (SS). Thanks to the status bits a system can put the stack in a separate memory.

hlt stops the processor. In maximum mode the 8086 gives the code S2' S1' S0' = 011; the 8288 generates no command for this code and only gives an ALE pulse. In minimum mode the processor announces that it has entered the halt state with a single ALE pulse and no control signal. The processor leaves this state only through an interrupt or RESET.

Table 10.1.9: Trace of the status-code program (data cycles only; each instruction also has fetch cycles with code 100).
InstructionS2' S1' S0'CycleS4 S38288 commandPAAXSP
mov bx,0200h100code fetch10 (CS)MRDC'CS:0100h0000hFFFEh
mov ax,[bx]101memory read11 (DS)MRDC'07200h1234hFFFEh
mov [bx+2],ax110memory write11 (DS)MWTC', AMWC'07202h1234hFFFEh
in al,60h001I/O read10IORC'port 0060h125AhFFFEh
out 61h,al010I/O write10IOWC', AIOWC'port 0061h125AhFFFEh
push ax110memory write01 (SS)MWTC', AMWC'16FFCh125AhFFFCh
hlt011halt—none—125AhFFFCh

The register and memory values in Table 10.1.9 come out the same when the program is run in emu8086. In the final state AX = 125Ah and SP = FFFCh; the word at 07202h is 1234h and the word pushed on the stack is 125Ah. The status codes and the 8288 commands, however, are not visible in the emulator; they follow from the rules in Table 10.1.7 and Table 10.1.8. Between cycles the pins return to the code 111 (passive).

10.1.4.4Decoding the status code

From the values of the five status pins, the type of the cycle and the segment used are found in three steps. First S2' is looked at: if 1 it is memory, if 0 I/O or a special cycle. Then the pair S1' S0' is read: 01 read, 10 write, 00 and 11 special cases. Finally S4 S3 gives the segment.

Example 10.1.9

A logic analyzer shows S2' S1' S0' = 1 0 1 and S4 S3 = 1 1 during T2. What is the cycle and which instruction might have produced it?

  1. S2' = 1 → a memory cycle.
  2. S1' S0' = 01 → a read. The code 101 is "memory read"; the 8288 generates MRDC'.
  3. S4 S3 = 11 → the segment is DS.

Any instruction that reads memory through DS produces this cycle: MOV AL, [BX], ADD AX, [SI], LODSB and the like. Had the code been 100, the cycle would be an instruction fetch and S4 S3 = 10 (CS) would be seen.

10.1.4.5QS1, QS0: the queue status

The prefetch queue of the 8086 is inside the chip. The bytes entering the queue are visible on the bus, but from outside it cannot be known when a given byte starts being executed. In maximum mode pins 24 and 25 give this information to the outside.

Table 10.1.10: The QS1 and QS0 queue status codes.
QS1QS0Meaning
00no operation: the queue did not change in this cycle
01the first byte of an opcode was taken from the queue
10the queue was flushed (a branch)
11a subsequent byte was taken from the queue

The queue status is valid in the clock cycle that follows the cycle in which the queue operation was done. The main user of the codes in Table 10.1.10 is the 8087 coprocessor. The 8087 listens to the same bus as the 8086 and copies the fetched instruction bytes into its own queue. With the QS codes it follows which byte the 8086 has taken for execution. When it sees that the byte leaving the queue is an ESC (escape) instruction, it executes that instruction itself. The code 01 reports that a new instruction has started, the code 11 the later bytes of the same instruction. The code 10 shows that the queue was flushed after a branch; the 8087 then clears its own copy.

10.1.5Control pins

The address and data pins answer the questions "where" and "what". The control pins answer "when" and "how". Is the transfer a read or a write, with memory or with I/O? In which direction will the transceiver turn on, will the bus be given to another master? This section begins with the read/write and transceiver signals of minimum mode and traces the bus cycles of two instructions signal by signal. It then completes the picture with the HOLD/HLDA, RQ'/GT and LOCK' pins that make bus sharing possible, with a semaphore program that uses the LOCK prefix, and with the TEST' input.

10.1.5.1RD', WR' and M/IO'

RD' (pin 32) is an active-low output and tells that the processor is reading from memory or I/O. It is 0 in the T2, T3 and Tw cycles of a read cycle. This pin exists in both modes. WR' (pin 29, minimum mode) is the write pulse; it is 0 in the T2, T3 and Tw cycles of a write cycle. The data sheet stresses a subtle difference between the two signals: WR' falls at the start of T2, while RD' falls slightly later within T2 to give the bus time to float.

M/IO' (pin 28, minimum mode) separates a memory access from an I/O access: 1 means memory, 0 means I/O. The signal becomes valid in T4 before the cycle and does not change until the last T4 of the cycle. Address decoders thus know which address space is selected before the address has even been latched. The condition M/IO' = 1 is added to the select logic of the memory chips and M/IO' = 0 to that of the I/O devices. On the 8088 this signal has the opposite polarity and is called IO/M': 1 means I/O, 0 means memory. It was chosen this way for compatibility with the 8085.

Table 10.1.11: The four basic operations with M/IO', RD' and WR' (minimum mode).
M/IO'RD'WR'OperationExample instruction
101memory readMOV AL, [BX]
110memory writeMOV [BX], AL
001I/O readIN AL, 60h
010I/O writeOUT 43h, AL

In Table 10.1.11 RD' and WR' are never 0 together in any row; the processor cannot read and write at the same time. Four separate command signals can be derived from these three signals. For example the memory read command is obtained with an OR gate: MEMR' = RD' + (M/IO')'. The output is 0 only when RD' = 0 and M/IO' = 1. The 8288 in maximum mode generates the same four signals (MRDC', MWTC', IORC', IOWC') from the status code.

Example 10.1.10

Let us generate the signals MEMR', MEMW', IOR' and IOW' with gates from the signals RD', WR' and M/IO' in minimum mode. All four signals are active low.

  1. MEMR' must be 0 only when RD' = 0 and M/IO' = 1: MEMR' = RD' + (M/IO')'. M/IO' is passed through a NOT gate and ORed with RD'.
  2. MEMW' = WR' + (M/IO')': 0 when WR' = 0 and M/IO' = 1.
  3. IOR' = RD' + M/IO': 0 when RD' = 0 and M/IO' = 0.
  4. IOW' = WR' + M/IO': 0 when WR' = 0 and M/IO' = 0.

Check: in the OUT 43h, AL cycle M/IO' = 0, RD' = 1, WR' = 0. MEMR' = 1 + 1 = 1, MEMW' = 0 + 1 = 1, IOR' = 1 + 0 = 1, IOW' = 0 + 0 = 0. Only IOW' is active. A 74LS32 and a 74LS04 are enough for this decoder.

10.1.5.2DT/R' and DEN'

In a system that uses 8286 or 74LS245 transceivers on the data bus, the processor has to generate two more signals: the direction of the transceiver and when it is turned on.

DT/R' (data transmit / receive, pin 27) is connected to the direction input of the transceiver. When it is 1 the data flows from the processor out (write), when 0 from outside into the processor (read). Its timing is the same as that of M/IO': it becomes valid in T4 before the cycle and stays through the cycle. It is logically equivalent to S1' in maximum mode.

DEN' (data enable, pin 26) is connected to the output-enable (OE') input of the transceiver. It is active low in memory and I/O accesses and in interrupt-acknowledge cycles. It is 0 from the middle of T2 to the middle of T4 in a read and in an interrupt acknowledge, and from the start of T2 to the middle of T4 in a write. In T1 it must be 1: at that moment the AD pins carry the address, and if the transceiver were on, the address would leak onto the data bus.

8086AD15–AD08286transceiverD15–D0memory / I/OOE' ← DEN' · T ← DT/R'
Figure 10.1.17: The 8286 transceiver: the DEN' output enables it (OE'), DT/R' selects the data direction (T).

Figure 10.1.17 summarizes the connection. While DEN' = 0 the transceiver is on and DT/R' selects its direction. In a read DT/R' = 0 and the data flows from memory to the processor; in a write DT/R' = 1 and the data flows from the processor to memory. While DEN' = 1 both sides float; the processor's AD pins and the system data bus are isolated from each other.

Common mistake

Turning the transceiver on in a read at the same time as RD', or even before it, creates contention. In a read DEN' falls in the middle of T2, that is, after the processor has released the AD pins. Had the transceiver turned on earlier, the address that the processor is still driving and the data that the transceiver starts driving would collide on the same lines. In a write there is no such danger; that is why DEN' falls at the start of T2 in a write.

10.1.5.3From instruction to bus cycles: OUT and IN

The execution of one instruction consists of several bus cycles: first the instruction bytes are fetched, then the instruction's own data cycle is made. The two instructions below are suited to tracing this chain with minimum-mode signals. CS = 01A7h and AL = 12h are assumed; when port 9Ah is read it supplies the value 3Ch.

; CS = 01A7h, AL = 12h
; PA      bytes  instruction
01A88h  E6 59  out 59h, al
01A8Ah  E4 9A  in  al, 9Ah

The offsets of the instructions are IP = 0018h and 001Ah. The physical addresses are 01A70h + 0018h = 01A88h and 01A70h + 001Ah = 01A8Ah. The instruction out 59h, al is encoded as E6 59: E6 is the opcode "write AL to the port with a fixed number" and 59h is the port number. in al, 9Ah is E4 9A. To keep the trace simple, the cycles are assumed to be made in sequence.

  1. Cycle 1, T1 (code fetch): The address 01A88h is even: BHE' = 0, A0 = 0 and a word is fetched in a single cycle. M/IO' = 1, ALE = 1, DT/R' = 0 (read), DEN' = 1.
  2. Cycle 1, T2–T4: RD' = 0, DEN' = 0. The memory supplies the word: E6h (the opcode) at the even address comes over D7–D0, and 59h (the port) at the odd address over D15–D8. The two bytes enter the queue.
  3. Cycle 2, T1 (I/O write): M/IO' = 0. The address is meaningful only on A7–A0 (59h); A15–A8 and A19–A16 are zero. The port number is odd: BHE' = 0, A0 = 1. Because it is a write, DT/R' = 1.
  4. Cycle 2, T2–T4: WR' = 0, DEN' = 0. The 12h in AL goes out over D15–D8; an odd address corresponds to the high bank. An output port usually latches the data on the rising edge of WR'.
  5. Cycle 3, T1 (code fetch): The next instruction is at 01A8Ah (even): again a word is fetched in a single cycle. M/IO' = 1, DT/R' = 0.
  6. Cycle 3, T2–T4: E4h (IN AL, imm8) is read from D7–D0 and 9Ah (the port) from D15–D8.
  7. Cycle 4, T1 (I/O read): The port address 009Ah is even: with BHE' = 1, A0 = 0 only the low bank is selected. M/IO' = 0, DT/R' = 0.
  8. Cycle 4, T2–T4: RD' = 0, DEN' = 0. The port puts the value 3Ch on D7–D0; the value is taken into AL at the start of T4: AL = 3Ch.
Table 10.1.12: The bus cycles of the OUT and IN instructions (minimum mode, no wait states).
CycleTypeA19–A0BHE'A0D15–D8D7–D0M/IO'RD'WR'DT/R'AL
1code fetch01A88h0059hE6h101012h
2I/O write00059h0112h—010112h
3code fetch01A8Ah009AhE4h101012h
4I/O read0009Ah10—3Ch00103Ch

Table 10.1.12 collects the T2–T4 values of the four cycles; in T1, RD' and WR' are 1, DEN' is 1 and ALE is 1. The bus activity is 4 cycles × 4 T = 16 clock cycles. At 5 MHz that is 3.2 µs. When the program is run in emu8086, the machine codes (E6 59, E4 9A) and the final value of AL, 3Ch, come out the same; the emulator does not show the pins.

This trace is a simplified sequential model. In reality the BIU prefetches code whenever at least two bytes of room open up in the queue. Cycle 3 may have been made before cycle 2; if the queue is empty, some fetches may also slip into idle cycles. The types of the cycles and the pin values do not change, only their order may.

Common mistake

Connecting an 8-bit peripheral only to D7–D0 and giving it an odd port address does not work. A byte at an odd port address is transferred over D15–D8; a device connected to D7–D0 never sees this data. The data sheet therefore asks that all the registers of an 8-bit device connected to the lower half be given even addresses. If the device is connected to the upper half, its registers are given odd addresses.

10.1.5.4HOLD and HLDA

The processor is not the only device that uses the bus. A direct memory access (DMA) controller, for example the 8237, can write data coming from a disk controller straight to memory without passing it through the processor. For this it has to take the bus over from the processor for a while. In minimum mode this handover is done with the HOLD and HLDA pins.

Definition 10.1.10

HOLD (pin 31) is an active-high input that tells that another bus master wants the local bus. The processor finishes the bus cycle it is in. In the middle of a T4 or Ti cycle it gives its acknowledgement by making the HLDA (hold acknowledge, pin 30) output 1. With the acknowledgement it floats the address, data and control pins. When HOLD falls to 0 it drops HLDA and takes the bus back.

T3T4TiTiTiT1CLKHOLDHLDA8086 drives8086Busesfloat: DMA controller drivesT3T4TiTiTiT1CLKHOLDHLDA8086 drives8086Busesfloat: DMA controller drives
Figure 10.1.18: Handing over the bus with HOLD/HLDA. Top: the processor finishes its cycle and releases the bus with HLDA = 1 in the middle of T4; the pins float. Bottom: when HOLD = 0 the processor drops HLDA, takes the bus back and starts a new cycle.

Figure 10.1.18 shows the steps of the handover. The DMA controller makes HOLD 1. The processor does not cut the current bus cycle short; the cycle finishes and HLDA = 1 in the middle of the next T4 or Ti. At the same moment AD0–AD15, A16–A19, BHE', RD', WR', M/IO', DT/R' and DEN' go into the float state. ALE, however, never floats; it stays at 0 in the meantime. The DMA controller now drives the bus itself.

While the bus is handed over, the processor does not stop entirely. The EU can go on executing the instructions waiting in the queue. It waits only when it comes to a job that needs the bus, that is, a memory access or the queue running empty so that a new fetch is needed. Long-running register instructions such as multiplication can overlap with the DMA.

The data sheet also lists the cycles in which a HOLD request is not granted immediately. If the request comes after T2, it is granted at the first suitable moment after the cycle ends. If the first half of a word at an odd address is being transferred, the bus is not released before the second half is done too. No handover is made between the two cycles of the interrupt-acknowledge sequence, and the bus is not released while an instruction with the LOCK prefix is being executed. The HOLD input is not synchronized internally; if the setup time cannot be met, it must be synchronized to the clock outside with a flip-flop.

Example 10.1.11

In a 5 MHz minimum-mode system the DMA controller makes HOLD = 1 in T1 of a memory read cycle. When is the bus handed over at the earliest?

  1. The processor finishes the cycle it has started: the cycles T2, T3 and T4 follow.
  2. HLDA becomes 1 in the middle of T4. From the start of T1 to this moment 3.5 cycles pass: 3.5 × 200 = 700 ns.
  3. If the cycle were the first half of a word at an odd address, the cycle of the second half would also be waited for and the delay would be 4 cycles longer.

The response time of DMA therefore varies between a few hundred nanoseconds and a few microseconds; long instructions with LOCK stretch this time.

10.1.5.5RQ'/GT0', RQ'/GT1' and LOCK'

In maximum mode the bus handover is done not with HOLD/HLDA but with the RQ'/GT0' (pin 31) and RQ'/GT1' (pin 30) pins. Their names come from the words request and grant. These pins are used by other local bus masters such as the 8087 or the 8089. Each pin is bidirectional and carries out a three-pulse handshake on a single line:

  1. The master that wants the bus gives a 0 pulse one clock cycle wide on the line: the request (RQ).
  2. In a T4 or T1 cycle the 8086 gives a pulse one cycle wide on the same line: the grant (GT). It floats the local bus and enters the bus handover state on the next clock cycle.
  3. When the master has finished its job it gives a third pulse on the line: the release. The 8086 takes the bus back on the next cycle.

After every handover between two masters there must be one idle clock cycle. The RQ'/GT0' pin has a higher priority than the RQ'/GT1' pin: if two requests arrive at the same time, the master attached to GT0 gets the bus first. The pins have pull-up resistors inside; if unused they can be left unconnected. Bidirectional communication on a single line saves pins: HOLD and HLDA in minimum mode take two pins, while here two separate masters are supported with two pins.

Definition 10.1.11

LOCK' (pin 29, maximum mode) is an active-low output that asks the other bus masters not to take the system bus. It is active while an instruction written with the LOCK prefix is executed: it becomes 0 in the clock cycle after the prefix is decoded and returns to 1 at the end of the last bus cycle of the prefixed instruction. In the interrupt-acknowledge sequence it is also active automatically, from T2 of the first cycle to T2 of the second.

While LOCK' is active, a request that arrives on an RQ'/GT pin is recorded but accepted only after the lock ends. All the bus cycles of the prefixed instruction are thus made back to back, with no other master slipping in between. In multiprocessor systems the LOCK' signal is connected to the arbiter that manages the shared bus (for example the 8289 bus arbiter) and makes sure that the system bus is not released for the duration of the lock either.

10.1.5.6Code trace: a semaphore with LOCK XCHG

If two processors use a shared region of memory, only one of them may enter that region at a time. For this a flag, a semaphore, is kept in the shared memory: 0 means "free", 1 means "busy". A processor that wants to enter the region reads the flag; if it is 0 it makes it 1 and enters. The other processor must not slip in between the read and the write. A XCHG with the LOCK prefix provides this.

org 100h
mov bx, offset flag
retry: mov al, 1
lock xchg al, [bx]   ; read + write
cmp al, 0             ; was it free?
jne retry            ; busy: retry
; ... critical section ...
mov byte ptr [bx], 0  ; release
ret
flag db 0

The program is in .COM form and starts at 100h. The instruction lengths are as follows: mov bx, offset flag 3 bytes (BB 10 01), mov al, 1 2 bytes, lock xchg al, [bx] 3 bytes (F0 86 07), cmp al, 0 2 bytes, jne retry 2 bytes, mov byte ptr [bx], 0 3 bytes and ret 1 byte. The 16 bytes of code in total fill 100h–10Fh; the variable flag is at 0110h. BX = 0110h.

mov al, 1 puts the "busy" value to be written to the flag in AL. lock xchg al, [bx] makes two bus cycles: first it reads the flag, then it writes the 1 in AL to the flag and puts the old value read into AL. The byte F0 is the LOCK prefix. Once the prefix is decoded LOCK' = 0, and for the two cycles the RQ'/GT request of the other master is not accepted. No other processor can slip in between the read and the write.

8086AL01hLOCK'0read (MRDC')flag0 (free)other CPU (RQ/GT)cannot take the buscritical section: —8086AL00hLOCK'0write (MWTC')flag1 (busy)other CPU (RQ/GT)cannot take the buscritical section: ours
Figure 10.1.19: A semaphore with LOCK'. Left: lock xchg has started, LOCK' = 0; the first bus cycle reads the flag (0) and the other master's request is not accepted during this time. Right: the second cycle writes the 1 in AL to the flag; AL receives the old value (0).

When XCHG is done LOCK' returns to 1 and the bus can be shared again. cmp al, 0 tests the old value: since the old value was 0, ZF = 1. jne retry does not jump because ZF = 1; the flag was free and is now this processor's. Had the other processor run the same code, XCHG would have returned 1 to it, ZF = 0, and it would have kept waiting in the loop. When the critical section is over, mov byte ptr [bx], 0 releases the semaphore by writing 0 to the flag.

Table 10.1.13: Trace of the semaphore program (the flag is initially 0).
InstructionBus cyclesLOCK'ALflag [0110h]ZF
mov bx, offset flag—100h00
mov al, 1—101h00
lock xchg al, [bx] (read)memory read001h00
lock xchg al, [bx] (write)memory write000h10
cmp al, 0—100h11
jne retry— (no jump)100h11
mov byte ptr [bx], 0memory write100h01

The values in Table 10.1.13 come out the same when run in emu8086. After the XCHG, AL = 00h and the flag at 0110h is 1. After the CMP, ZF = 1; after the last instruction the flag is 0 again. There is no other processor in the emulator and the LOCK' pin is not visible; the effect of the lock has been traced according to the rule in the data sheet. CMP also sets PF = 1: the result is 00h and the number of one bits (0) is even.

Common mistake

Building the semaphore from separate instructions with MOV AL, [BX], CMP AL, 0 and MOV [BX], 1 does not work in a two-processor system. Between the read and the write the other processor can take the bus and read the same 0. Both see the flag as free and both enter the critical section. Even XCHG is not safe without the LOCK prefix: the bus can be handed over with RQ'/GT between the read and write cycles of the XCHG.

10.1.5.7TEST'

TEST' (pin 23) is an active-low input that the WAIT instruction tests. If TEST' = 0 while the processor executes WAIT, it goes on to the next instruction at once. If TEST' = 1 it waits idle and tests the pin again; it executes WAIT over and over until TEST' becomes 0. This wait uses no bus cycles. The input is synchronized internally on the rising edge of every clock cycle; according to the data sheet it must stay active for at least 5 clock cycles.

The typical user of the TEST' input is the 8087. The BUSY output of the 8087 is connected to the TEST' input of the 8086. While the 8087 is executing a floating-point operation, BUSY = 1. Before reading the result, the 8086 executes FWAIT (the same instruction as WAIT) and waits for the 8087 to finish. If interrupts are enabled, an interrupt may arrive during the wait; the processor services the interrupt and on return executes WAIT again.

10.1.6Clock, reset and power

Three things are needed for a processor to work: a stable supply, a regular clock and a well-defined starting moment. In the 8086, the clock and reset signals are prepared by the 8284A clock generator. This section describes the CLK pin, the RESET pin and where the processor fetches its first instruction after reset, and then the internal functions of the 8284A.

10.1.6.1CLK

CLK (pin 19) is the clock input that provides the basic timing of the processor and the bus control. The clock of the 8086 is not symmetric: the duty cycle is 33%. The clock is 1 for one third of a period and 0 for two thirds. According to the data sheet this asymmetry was chosen to optimize the internal timing. Some operations inside the processor are placed in the long low phase of the clock, some in the short high phase.

T = 200 ns (5 MHz)high ≈ 67 ns (1/3)low ≈ 133 ns (2/3)CLK
Figure 10.1.20: The 33% duty-cycle clock from the 8284A (5 MHz): period 200 ns, high phase about 67 ns, low phase about 133 ns.

The 8086 was produced in three speed grades: the 8086 runs at 5 MHz, the 8086-2 at 8 MHz and the 8086-1 at 10 MHz. The values TCLCH and TCHCL in Table 10.1.6 limit this asymmetry. At 5 MHz the low phase must be at least 118 ns and the high phase at least 69 ns. In a perfect 33% clock these values are 133 and 67 ns; the lower limit of 118 ns leaves a little margin. The lower limit of 69 ns for the high phase, however, is slightly above 67 ns. The duty cycle of the clock generator is therefore kept not exactly one third but very close to it. It is hard to produce such a clock with an ordinary oscillator; the 8284A is designed for this job.

10.1.6.2RESET, VCC and GND

Definition 10.1.12

RESET (pin 21) is an active-high input that ends the processor's current activity at once. The signal must stay 1 for at least four clock cycles; at power-up, RESET must fall to 0 at least 50 µs after the supply has settled. While RESET stays 1 the processor sleeps. When RESET falls to 0, an internal start-up sequence of about 10 clock cycles runs, and then the processor begins executing at the instruction at address FFFF0h.

On the rising edge of RESET the processor cuts off all bus operations. All tri-state outputs float; ALE and HLDA are driven to 0. Some of the registers are set to fixed values and the rest remain undefined. These fixed values determine where the system designer must put the first instruction.

Table 10.1.14: The state of the processor after RESET.
ItemValue
CSFFFFh
IP0000h
DS, SS, ES0000h
FLAGScleared (IF = 0: interrupts disabled, TF = 0)
Prefetch queueempty
First instruction addressFFFFh × 10h + 0000h = FFFF0h

The first instruction address in Table 10.1.14, FFFF0h, is the start of the last 16 bytes of the 1 MB address space. Permanent memory, that is, ROM (the BIOS), must be at this address; the contents of RAM are random at power-up. 16 bytes are far too few for a start-up program. So FFFF0h usually holds a far JMP to the real start-up code in ROM. Because IF = 0, the start-up code runs without being interrupted; the interrupt vector table has not been set up yet and an interrupt would mean a crash.

VCC (pin 40) is the +5 V DC supply. There are two pins for GND: 1 and 20. The two ground pins share the large current pulses drawn when the outputs switch at the same time. If a sudden current passes through the thin bond wire of a single ground pin, the wire's inductance creates jumps in the ground level. This is called ground bounce. Two pins reduce this noise. On the board, a 0.1 µF decoupling capacitor is placed next to the supply pins.

Common mistake

It is wrong to think that after reset the processor starts from address 00000h. The range 00000h–003FFh is the interrupt vector table and is in RAM. The 8086 starts with CS = FFFFh and IP = 0000h; the first physical address is FFFF0h. The same address can also be written with another segment:offset pair such as F000h:FFF0h, but the values the 8086 loads are FFFFh and 0000h.

10.1.6.3The first instruction after RESET: step by step

What the processor does from RESET to the first BIOS code can be traced in eight steps. The example takes the first instruction used in the BIOS of the IBM PC: a five-byte far jump at FFFF0h, EA 5B E0 00 F0.

; RESET = 1 (≥ 4 clock cycles)
; CS ← FFFFh, IP ← 0000h
; DS, SS, ES ← 0000h
; FLAGS ← 0000h ; IF = 0
; the queue is flushed
; RESET 1 → 0
; fetch FFFF0h   ; EA 5B E0 00 F0
jmp far F000h:E05Bh
; fetch FE05Bh   ; BIOS
  1. The RESET pin is held at 1 for at least four clock cycles. The processor drops what it is doing at once; the contents of the registers are undefined.
  2. The hardware loads CS = FFFFh, IP = 0000h. The programmer does not choose these values; they are built into the processor.
  3. The other segment registers DS, SS and ES become 0000h.
  4. The flags are cleared: since IF = 0, interrupts are disabled.
  5. The queue is flushed. When RESET falls to 0, the BIU starts the first fetch.
  6. The first address is FFFFh × 10h + 0000h = FFFF0h. The five-byte far jump in ROM sits here: EA 5B E0 00 F0.
  7. EA is the opcode of the far JMP. It is followed first by the offset (E05Bh), then by the segment (F000h); both are written little-endian: 5B E0 → E05Bh, 00 F0 → F000h. When the JMP executes, CS:IP = F000h:E05Bh and the queue is flushed again.
  8. The new physical address is F0000h + E05Bh = FE05Bh. In the IBM PC the start-up code of the BIOS is at this address; the start-up program that does not fit in 16 bytes continues from here.
CSFFFFhIP0000hDS/SS/ES0000hFLAGS0000h1 MB memory (top)FFFF0h: EA 5B E0 00 F0FFFFFh = last byteFE05Bh: BIOS codeROM (BIOS)address bus: FFFF0hCSF000hIPE05BhDS/SS/ES0000hFLAGS0000h1 MB memory (top)FFFF0h: EA 5B E0 00 F0FFFFFh = last byteFE05Bh: BIOS codeROM (BIOS)address bus: FE05Bh
Figure 10.1.21: The first instruction after RESET. Left: the first address is FFFF0h, the last 16 bytes of the 1 MB; EA 5B E0 00 F0 is in ROM. Right: after the far JMP, CS:IP = F000h:E05Bh, the new address is FE05Bh (BIOS code).
Table 10.1.15: The registers from RESET to the BIOS code.
StepCSIPDS/SS/ESFLAGSAddress bus
RESET = 1????????????????floats
CS, IP are loadedFFFFh0000h????????—
the segments are zeroedFFFFh0000h0000h????—
the flags are clearedFFFFh0000h0000h0000h—
first fetchFFFFh0000h0000h0000hFFFF0h
jmp far F000h:E05BhF000hE05Bh0000h0000h—
BIOS code is fetchedF000hE05Bh0000h0000hFE05Bh

Table 10.1.15 summarizes the steps through the registers. The first fetch starts at FFFF0h; the address is even and the BIU fills the queue word by word: FFFF0h, FFFF2h, FFFF4h. After the far jump the queue is flushed and the fetch continues from FE05Bh. Because this address is odd, in the first fetch the BIU takes a single byte, and then continues to fetch words from even addresses.

10.1.6.4The 8284A clock generator

The 8284A is an 18-pin clock generator designed for the 8086 and 8088. It has three jobs: to generate the CLK signal with a 33% duty cycle, to synchronize READY with the clock and to synchronize RESET with the clock.

8284Aclock generatorCrystal15 MHzX1X2RC circuitpower-onRES'Memory/I/ORDY1, AEN1'8086CLKCLK (19)READYREADY (22)RESETRESET (21)5 MHz, 33%OSC = 15 MHz, PCLK = 2.5 MHz (peripherals)
Figure 10.1.22: The wiring of the 8284A clock generator: a 15 MHz crystal on X1–X2, the memory/I/O ready signal on the RDY1 and AEN1' inputs, the power-on RC circuit on the RES' input. The outputs CLK, READY and RESET go to the 8086; OSC and PCLK are for peripherals.

Clock generation starts with a crystal. The crystal connected to the X1 and X2 pins drives the oscillator inside the 8284A. The 8284A divides this frequency by 3: a 15 MHz crystal gives a 5 MHz CLK. Dividing by three also produces the 33% duty cycle by itself: the output is 1 for one of three crystal periods and 0 for two. The oscillator frequency is also given at the OSC output; the PCLK output is a peripheral clock at half the frequency of CLK with a 50% duty cycle. With a 15 MHz crystal, OSC = 15 MHz and PCLK = 2.5 MHz. If the F/C' input is made 1, the clock is taken from an external source on the EFI input instead of the crystal.

Example 10.1.12

In the IBM PC a 14.31818 MHz crystal is connected to the 8284A. What are CLK, the clock period and the duration of a bus cycle without wait states? How many MHz is PCLK?

  1. CLK = 14.31818 / 3 = 4.77273 MHz.
  2. T = 1 / 4.77273 MHz ≈ 209.5 ns.
  3. The bus cycle is 4 × 209.5 ≈ 838 ns.
  4. PCLK = CLK / 2 ≈ 2.386 MHz.

14.31818 MHz is four times the colour subcarrier of colour television (3.579545 MHz). IBM lowered the cost by using this crystal for both the processor clock and the video card. The same computation holds in 8086 systems.

The second job of the 8284A is READY. The ready signals of memory and I/O devices are connected to the RDY1 or RDY2 inputs; the AEN1' and AEN2' inputs select which RDY input is valid. This arrangement serves to handle the ready signals of two separate bus masters with a single 8284A. The ASYNC' input determines whether the synchronization will be one or two stages. The 8284A samples RDY on the clock edges and gives the 8086 a READY signal that meets the setup and hold conditions. Because the READY input of the 8086 is not synchronized internally, this step is mandatory.

The third job is RESET. At power-up the supply rises from 0 V to 5 V in a few milliseconds. An RC circuit connected to the RES' input creates a slowly rising voltage at this input while the capacitor charges. The RES' input has a Schmitt trigger: when the voltage passes a certain threshold the output changes with a clean edge, and the slowly rising voltage does not turn into a noisy signal. The 8284A synchronizes this signal with the clock and gives it to the 8086 as the active-high RESET. A "reset" button on the board triggers the same circuit by discharging the capacitor.

Example 10.1.13

An RC circuit with R = 10 kΩ and C = 10 µF is connected to the RES' input. Let the Schmitt threshold of the RES' input be about 1.7 V (VCC = 5 V). How long does RESET stay active after power is applied?

  1. The capacitor voltage rises as v(t) = 5 · (1 − e−t/RC); RC = 10,000 × 10 × 10−6 = 0.1 s.
  2. For v(t) = 1.7 V: 1 − e−t/RC = 0.34 → e−t/RC = 0.66 → t = −0.1 · ln 0.66 ≈ 0.0416 s.
  3. RESET stays active for about 42 ms. This is far longer than the 50 µs the data sheet asks for and also leaves time for the supply to settle.

The threshold should be taken from the 8284A data sheet; an approximate value is used here to show the method of computation.

10.1.7Maximum mode

Minimum mode is sufficient for small single-processor systems. When an 8087 coprocessor, an 8089 I/O processor or a second 8086 is added to the system, a separate chip must generate the control signals. The 8086 too needs pins that support bus sharing. This section once more collects the pins that change with the mode, and then describes the 8288 bus controller and a complete maximum-mode system.

10.1.7.1MN/MX' and the pins by mode

In minimum mode (MN/MX' = 1) pins 24–31 carry these signals:

  • ALE (25): address latch enable. It is an active-high pulse in T1 of every bus cycle and loads the 8282/8283 latches. The data sheet specifically notes that ALE never floats: even when the bus is handed over, ALE keeps being driven.
  • INTA' (24): interrupt acknowledge.
  • DEN', DT/R', M/IO', WR' (26–29): transceiver control and the memory/I/O distinction.
  • HOLD, HLDA (31, 30): bus handover (DMA).

In maximum mode (MN/MX' = 0) the same pins turn into these signals:

  • S2', S1', S0' (28–26): the cycle type; the 8288 generates the control signals from this code.
  • QS1, QS0 (24, 25): the queue status; for the 8087.
  • LOCK' (29): locks the bus.
  • RQ'/GT0', RQ'/GT1' (31, 30): bus request and grant.

There is a reason ALE does not float. When the bus is handed over, another master drives the address with its own latches or directly. Had ALE of the 8086 floated, the undefined level set by pull-up resistors could have made the latches transparent by mistake. With ALE driven at 0, the latches of the 8086 stay closed and the address is not corrupted during a bus handover.

10.1.7.2The 8288 bus controller

Definition 10.1.13

The 8288 bus controller is the 20-pin chip that, in maximum mode, decodes the S2'–S0' status code of the 8086. From this code it generates the memory and I/O command signals (MRDC', MWTC', AMWC', IORC', IOWC', AIOWC', INTA') and the bus control signals (ALE, DEN, DT/R', MCE/PDEN').

StatusdecoderCommand signalgeneratorControllogicControl signalgeneratorS0'S1'S2'from 8086CLKAEN'CENIOBMRDC'MWTC'AMWC'IORC'IOWC'AIOWC'INTA'DT/R'DENMCE/PDEN'ALE
Figure 10.1.23: The internal structure of the 8288 bus controller: the status decoder decodes the S2'–S0' code, the control logic sets up the timing with the CLK, AEN', CEN and IOB inputs; the command and control signal generators give the outputs.

The inputs of the 8288 are the status pins of the 8086 and the clock of the 8284A. The status decoder inside decodes the code in Table 10.1.7. The control logic sets up the timing of the commands with the clock. The outputs are in two groups:

  • Command signals: MRDC' (memory read), MWTC' (memory write), IORC' (I/O read), IOWC' (I/O write) and INTA' (interrupt acknowledge). AMWC' and AIOWC', which begin with "A", are "advanced" write signals: they start one clock cycle before the normal write signal. They exist so that a slow memory or I/O device can start the write early.
  • Control signals: ALE, DEN and DT/R' now come from the 8288. DEN is active high here; an inverter may be needed when connecting it to the transceiver. The MCE/PDEN' output is used for cascading interrupt controllers or for buffering the I/O bus separately.

The 8288 also has control inputs. While AEN' (address enable) is 1, the command outputs float; in a multiprocessor system the bus arbiter uses this input when it gives the bus to another processor. While CEN (command enable) is 0, the command outputs stay passive. While IOB (I/O bus mode) is 1, the 8288 generates the I/O commands for a local I/O bus. The 8086, whose pins are freed, uses the QS1, QS0, LOCK' and RQ'/GT pins in place of these signals.

Example 10.1.14

Which signals does the 8288 generate in the data cycle of the instruction MOV [BX], AX in maximum mode? BX points to an even address.

  1. In T4 of the previous cycle the 8086 gives S2' S1' S0' = 110 (memory write).
  2. The 8288 generates the ALE pulse in T1; the address is captured by the latches. DT/R' = 1 (transmit).
  3. AMWC' becomes 0 at the start of T2 and MWTC' one clock cycle later. DEN = 1 turns on the transceiver.
  4. In T3 the status pins return to passive (111); the 8288 ends the commands in T4.

In minimum mode the same cycle would be made with WR' = 0, M/IO' = 1, DT/R' = 1 and DEN' = 0; the function of the signals is the same, the chip that generates them is different.

10.1.7.3A maximum-mode 8086 system

8284A8086MN/MX' = 0CLKREADYRESET8288bus controllerS0'–S2'8282 latch8286 XCVRAD0–15ALEDEN, DT/R'Address busData busMRDC', MWTC' → memoryIORC', IOWC' → I/OINTA'8259A PICINT → INTR← IRQ0–7
Figure 10.1.24: A maximum-mode 8086 system: the 8284A provides the clock, the 8288 the command and control signals, the 8282 latches the address bus, the 8286 transceivers the data bus; the 8259A interrupt controller connects eight hardware interrupts (IRQ0–IRQ7) to INTR.

Figure 10.1.24 shows a complete maximum-mode system. The 8284A gives CLK to both the 8086 and the 8288; the two must work from the same clock. The S2'–S0' pins of the 8086 go to the 8288. The 8288 controls the 8282 latches with ALE and the 8286 transceivers with DEN and DT/R'; with the command signals it also drives memory and I/O. The 8259A programmable interrupt controller puts eight hardware interrupt requests in priority order, connects them to the INTR input and answers the INTA' pulses with the type number. If an 8087 is to be added to this system, it is connected to the QS1, QS0 and RQ'/GT0' pins; its BUSY output goes to the TEST' input.

Minimum-mode and maximum-mode systems are completely the same from the software's point of view. A program cannot tell which mode it is running in. The difference is only in the hardware design: the number of chips, the ability to share the bus and support for additional processors.

10.1.8Interrupt pins

The software side of hardware interrupts, that is, the vector table, IRET and interrupt service routines, is treated together with the interrupt mechanism. This section examines the same topic at the level of pins: through which pin and with what timing an interrupt request enters the processor, and through which bus cycles the processor reads the type number from the interrupt controller.

10.1.8.1INTR, NMI and INTA'

INTR (pin 18) is the maskable interrupt request input. It is active high and level triggered: the request is valid as long as the line is held at 1. The processor samples INTR in the last clock cycle of every instruction; in string instructions it also samples at the end of every single transfer. If IF = 1 it accepts the request and enters the interrupt-acknowledge cycles. If IF = 0 the request waits; this is why the CLI instruction disables INTR. The input is synchronized internally on the rising edge of every clock cycle.

NMI (pin 17) is the non-maskable interrupt input. It is edge triggered: a transition from 0 to 1 starts the request. The rising edge is latched inside the chip and serviced at the end of the current instruction. NMI always leads to a type 2 interrupt; the type number is not read from outside. It cannot be masked by software, that is, by IF, and has higher priority than INTR. The data sheet asks that NMI stay at 1 for at least two clock cycles. Its typical uses are a power-failure warning and a memory parity error.

INTA' (pin 24, minimum mode) is the read pulse of the interrupt-acknowledge cycles. It is an active-low output and is 0 in the T2, T3 and Tw cycles of every interrupt-acknowledge cycle. In maximum mode the INTA' signal is generated by the 8288.

Table 10.1.16: Comparison of the INTR and NMI pins.
PropertyINTR (18)NMI (17)
Triggeringlevel, active highrising edge
Maskingwith IF = 0 (CLI)cannot be masked
Samplingin the last clock cycle of an instructionthe edge is latched internally, serviced at the end of the instruction
Type numberread from D7–D0 in the second INTA' cyclealways 2
Acknowledge cycletwo INTA' cyclesnone
Useperipherals through the 8259Apower failure, parity error
Common mistake

Thinking INTR is edge triggered leads to two kinds of error. A short pulse is lost if it ends before the processor samples it; INTR must be held at 1 until it is accepted. On the other hand, if the request is still 1 when the service routine ends, the processor enters the same interrupt again. The source of the request must therefore drop its request when it sees the acknowledgement; the 8259A does this with the INTA' pulses. The one that is edge triggered is NMI.

10.1.8.2A hardware interrupt: the INTA cycles

When INTR = 1 and IF = 1, the processor runs two consecutive interrupt-acknowledge cycles after the current instruction ends. An interrupt-acknowledge cycle resembles a read cycle; the difference is that the INTA' signal becomes active instead of RD', and that the address bus floats.

T1T2T3T4T1T2T3T4INTA cycle 1 · INTA cycle 2INTRLOCK'INTA'type no.D7–D0data bus floats8259A drives the type numberT1T2T3T4T1T2T3T4INTA cycle 1 · INTA cycle 2INTRLOCK'INTA'type no.D7–D0data bus floats8259A drives the type number
Figure 10.1.25: The two INTA' cycles. Top, the first cycle: the INTA' pulse tells the interrupt controller that the request has been accepted; the data bus stays floating. Bottom, the second cycle: the 8259A puts the type number on D7–D0 and the processor reads it.
  1. The first INTA' cycle: The processor makes INTA' 0 throughout T2–T3. This pulse tells the interrupt controller (8259A) that the request has been accepted. The 8259A selects the highest-priority one among the pending requests and prepares the type number. In this cycle the data bus stays floating; no data is read. According to the data sheet BHE' is 0 in T1 of this cycle.
  2. The second INTA' cycle: In the second INTA' pulse the 8259A puts the type number on the D7–D0 lines. For example, for IRQ0 in the PC this number is 08h. The processor reads the byte at the start of T4.
  3. The vector: The processor multiplies the type number by 4 and finds the address in the interrupt vector table: 08h × 4 = 00020h. It reads the new IP from this address and the new CS from 00022h. It pushes FLAGS, CS and IP on the stack, clears IF and TF and jumps to the service routine.

In maximum mode LOCK' is automatically active so that no other bus master slips in between the two cycles. According to the data sheet LOCK' is 0 from T2 of the first cycle to T2 of the second. A bus handover request is not accepted until the end of the second cycle either. Had a DMA cycle come in between, the two-pulse handshake of the 8259A could have been disrupted.

Example 10.1.15

In a 5 MHz minimum-mode system the 8259A reports the IRQ1 (keyboard) request with type 09h. How many bus cycles and how much time do the two INTA' cycles and the vector read take? From which physical addresses is the service routine's address read?

  1. Two interrupt-acknowledge cycles: 2 × 800 ns = 1.6 µs. In the second cycle 09h is read from D7–D0.
  2. The vector address is 09h × 4 = 00024h. IP is read from 00024h and CS from 00026h; since both addresses are even, the two word reads take 2 cycles.
  3. Pushing FLAGS, CS and IP on the stack is 3 word writes; if the stack is at an even address, 3 cycles.
  4. In total at least 2 + 2 + 3 = 7 bus cycles: 7 × 800 ns = 5.6 µs. To this are added the internal operation cycles and the fetching of the first instructions of the service routine.

If the stack were at an odd address, every push would take two cycles and the time would be 3 cycles longer. This is why the data sheet recommends keeping the stack at an even address.

10.1.9Exercises and solutions

The eight exercises below use knowledge about pins, bus cycles and the clock together. The solution of each is given with its intermediate steps.

Example 10.1.16

The 8086 runs at 8 MHz. How many ns does a bus cycle without wait states take? What if two Tw are added?

  1. T = 1 / 8 MHz = 125 ns.
  2. A cycle without wait states: 4 × 125 = 500 ns.
  3. With two Tw: (4 + 2) × 125 = 6 × 125 = 750 ns.
Example 10.1.17

In minimum mode, when writing to a peripheral with OUT, what values do the pins M/IO', RD', WR' and DT/R' take in T2–T4 of the data cycle?

  1. The target is I/O: M/IO' = 0.
  2. The operation is a write: RD' = 1, WR' = 0.
  3. The data flows from the processor outward: DT/R' = 1.

DEN' is also 0 throughout T2–T4; in T1 it is 1.

Example 10.1.18

How many data bus cycles does MOV [2003h], AX need? What are BHE' and A0 in each cycle? (DS = 0000h.)

  1. The physical address 02003h is odd; the word is split into two cycles.
  2. Cycle 1: address 02003h, BHE' = 0, A0 = 1; AL is written to the high bank over D15–D8.
  3. Cycle 2: address 02004h, BHE' = 1, A0 = 0; AH is written to the low bank over D7–D0.

Run in emu8086 with AX = BEEFh, EFh is written to 02003h and BEh to 02004h.

Example 10.1.19

What is the difference between S2' S1' S0' = 1 0 0 and 1 0 1? Which command does the 8288 generate for each?

  1. 100: code (instruction) fetch. 101: data read.
  2. Both are reads from memory; the 8288 generates MRDC' for both.

The difference is not for the memory but for chips that watch the bus, such as the 8087 or debugging hardware; they have to tell instruction bytes from data reads.

Example 10.1.20

The 8259A reports the IRQ0 request with type 08h. What is seen on the data bus in the two INTA' pulses? In maximum mode, what is the state of LOCK' during this time?

  1. 1st pulse: the data bus floats; only the acknowledgement is given.
  2. 2nd pulse: the 8259A puts 08h on D7–D0; the processor reads it.
  3. LOCK' stays 0 (active) from T2 of the 1st cycle to T2 of the 2nd cycle.

The processor then reads the vector from address 08h × 4 = 00020h.

Example 10.1.21

What CLK frequency does the 8284A generate if the crystal is 24 MHz? For which 8086 version is this suitable?

  1. CLK = 24 / 3 = 8 MHz, T = 125 ns.
  2. 8 MHz is the speed of the 8086-2. The 5 MHz 8086 cannot be run with this clock: TCLCL must be at least 200 ns.
Example 10.1.22

In a system with T = 125 ns, TCLAV + TDVCL + tbuf = 120 ns is assumed. How many Tw are needed for a memory with an access time of 450 ns?

  1. tallowed = 3 × 125 − 120 = 375 − 120 = 255 ns.
  2. n = ⌈(450 − 255) / 125⌉ = ⌈195 / 125⌉ = ⌈1.56⌉ = 2.
  3. Check: with 1 Tw, 380 ns, not enough; with 2 Tw, 505 ns, enough.
  4. The cycle is 6 × 125 = 750 ns.
Example 10.1.23

In the I/O write cycle of the instruction OUT 9Bh, AL, what are A7–A0, BHE', A0 and the lines the data passes over?

  1. The port number goes out on the address lines: A7–A0 = 9Bh, A19–A8 = 0. M/IO' = 0.
  2. 9Bh is odd (1001 1011b, lowest bit 1): BHE' = 0, A0 = 1.
  3. A byte at an odd address goes to the high bank: AL goes out over D15–D8.

If this port were on an 8-bit device connected to D7–D0, it would never see the data.

10.1.10Summary

  • The package: The 8086 is a 16-bit HMOS processor in a 40-pin DIP package, working from a single +5 V supply (pin 40; ground 1 and 20). The apostrophe at the end of a name marks an active-low signal. The pins are divided into seven groups: power, clock/reset, address/data, address/status, interrupt, common control and mode-dependent pins.
  • Multiplexing: More than 60 signals fit on 40 pins through time-division multiplexing. AD0–AD15 carry the address in T1, then data; A16–A19 carry the address in T1, then S3–S6. On the falling edge of the ALE pulse the 8282/74LS373 latches capture the address; three latches are needed for 20 bits and BHE'. The 8286/74LS245 transceivers isolate the data bus and provide drive strength.
  • Banks: The 1 MB memory is divided into two 512 KB banks: even addresses on D7–D0 (A0 = 0), odd addresses on D15–D8 (BHE' = 0). A word at an even address takes one cycle, a word at an odd address two cycles; a byte access is always a single cycle.
  • The bus cycle: It consists of at least four T states: T1 address, T2 direction/control, T3 data, T4 finish. 800 ns at 5 MHz. In a write the data is on the pins from T2 on; in a read the AD pins float in T2 (bus turnaround) and the data is sampled at the start of T4.
  • READY: It is sampled during T3; if 0, a Tw is inserted between T3 and T4. The number of wait states is found with n = ⌈(taccess − tallowed) / T⌉; tallowed = 3T − TCLAV − TDVCL − tbuf. READY is given synchronized through the RDY input of the 8284A.
  • Status pins: S2' S1' S0' (maximum mode) encode the cycle type: 000 interrupt acknowledge, 001 I/O read, 010 I/O write, 011 HLT, 100 code fetch, 101 memory read, 110 memory write, 111 passive. S4 S3 give the segment (00 ES, 01 SS, 10 CS/none, 11 DS); S5 = IF, S6 = 0. QS1 QS0 report the queue status to the 8087.
  • Control pins: RD' and WR' are the read/write pulses, M/IO' separates memory from I/O. DT/R' controls the direction of the transceiver and DEN' its turning on; DEN' is 1 in T1. HOLD/HLDA (minimum) and RQ'/GT (maximum) hand the bus to another master. LOCK' locks the bus during a prefixed instruction; an indivisible semaphore is built with LOCK XCHG. TEST' is the input that the WAIT instruction waits on.
  • Clock and reset: The 8284A divides the crystal by 3 (15 MHz → 5 MHz), generates the CLK with a 33% duty cycle and synchronizes READY and RESET. RESET is held at 1 for at least 4 clock cycles; afterwards CS = FFFFh, IP = 0000h, DS = SS = ES = 0000h, the flags are clear (IF = 0) and the first instruction is fetched from FFFF0h.
  • Maximum mode: With MN/MX' = 0, pins 24–31 turn into QS1, QS0, S0'–S2', LOCK' and the RQ'/GT pins; the 8288 bus controller generates MRDC', MWTC', AMWC', IORC', IOWC', AIOWC', INTA', ALE, DEN and DT/R' from the status code.
  • Interrupt pins: INTR is level triggered, is masked by IF and is acknowledged with two INTA' cycles; the type number is read from D7–D0 in the second cycle. NMI is triggered by the rising edge, cannot be masked and is always type 2.

10.1.11Key terms

  • dual in-line package (DIP)
  • active low / active high
  • multiplexing
  • latch
  • buffer (bus transceiver)
  • tri-state output, high impedance
  • memory bank
  • aligned / unaligned access
  • bus cycle
  • T state
  • wait state (Tw)
  • idle state (Ti)
  • bus turnaround
  • access time
  • status code
  • minimum / maximum mode
  • bus controller (8288)
  • clock generator (8284A)
  • duty cycle
  • reset (RESET)
  • direct memory access (DMA)
  • bus master
  • semaphore
  • interrupt acknowledge (INTA)
  • non-maskable interrupt (NMI)
  • programmable interrupt controller (8259A)

10.1.12Test Yourself

  1. For the 8086-2 (8 MHz) the data sheet gives TCLAV ≤ 60 ns and TDVCL ≥ 20 ns; tbuf = 40 ns. How many wait states does a memory with an access time of 300 ns need, and how many ns does the cycle take?

    Answer

    T = 125 ns; tallowed = 375 − 60 − 20 − 40 = 255 ns. n = ⌈(300 − 255) / 125⌉ = ⌈0.36⌉ = 1. Check: with 0 Tw, 255 ns is not enough; with 1 Tw, 380 ns is enough. The cycle is 5 × 125 = 625 ns.

  2. With DS = 1000h, MOV [1FFFh], AX runs. To which physical addresses and in how many cycles is it written? What are BHE', A0 and the lines used in each cycle?

    Answer

    PA = 10000h + 1FFFh = 11FFFh, an odd address; two cycles. Cycle 1: 11FFFh, BHE' = 0, A0 = 1, AL over D15–D8. Cycle 2: 12000h, BHE' = 1, A0 = 0, AH over D7–D0.

  3. In maximum mode, what are S2' S1' S0' and S4 S3 in these cycles: the read of POP BX, the read of IN AL, DX, the write of MOV ES:[DI], AL?

    Answer

    POP BX: memory read 101, segment SS → 01. IN AL, DX: I/O read 001, no segment → 10. MOV ES:[DI], AL: memory write 110, segment ES → 00.

  4. In minimum mode, what values do M/IO', RD', WR', DT/R' and DEN' take in T2–T4 of an instruction fetch cycle? Are these values different from the data cycle of MOV AL, [BX]?

    Answer

    M/IO' = 1, RD' = 0, WR' = 1, DT/R' = 0, DEN' = 0. The values are the same as for a memory read; an instruction fetch cannot be told from a data read by the control pins. The distinction is made by the S4 S3 bits in T2–T4 (10 = CS in a fetch, 11 = DS in a read of [BX]) and, in maximum mode, by the status code (100 / 101).

  5. What happens if a D flip-flop chip that captures on the rising edge is used as the address latch and ALE is connected directly to its clock input? Explain with the timing values of the 5 MHz 8086.

    Answer

    The flip-flop captures the address on the rising edge of ALE. ALE rises at most TCLLH = 80 ns after the start of T1; the address becomes valid at most TCLAV = 110 ns after. At the moment of capture the address may not yet have settled and a wrong address is latched. The fix is to invert ALE and move the capture to the falling edge, or to use a transparent latch.

  6. A 30 MHz crystal is connected to the 8284A. What are the CLK, PCLK and OSC frequencies? How many ns does a bus cycle without wait states take, and about how many ns is the high phase of the clock?

    Answer

    CLK = 30 / 3 = 10 MHz (8086-1), PCLK = 5 MHz, OSC = 30 MHz. T = 100 ns; the bus cycle is 400 ns. The high phase is about T / 3 ≈ 33 ns, the low phase about 67 ns.

  7. After RESET the bytes EA 00 E0 00 F0 are at address FFFF0h. What does this instruction do, and from which physical address does the processor fetch the next instruction? What is IF at that moment?

    Answer

    EA is a far JMP. The offset 00 E0 → E000h, the segment 00 F0 → F000h. CS:IP = F000h:E000h, physical address F0000h + E000h = FE000h. Because reset clears the flags, IF = 0; interrupts are disabled.

  8. A semaphore is built with the sequence MOV AL, [BX] / CMP AL, 0 / JNE retry / MOV BYTE PTR [BX], 1. Why is it not safe in a two-processor system? How many bytes and which prefix fix it?

    Answer

    The read and the write are in separate instructions; in between, the other processor can take the bus and read the same 0, and both enter the critical section. The fix: MOV AL, 1 and LOCK XCHG AL, [BX]. XCHG does the read and the write in one instruction; the LOCK prefix (F0h, 1 byte) prevents the bus from being handed over between the two cycles.

  9. In minimum mode a DMA controller makes HOLD = 1 in T3 of a read cycle. Does the processor release the bus in T4 of this cycle?

    Answer

    No. According to the data sheet, for the bus to be released in T4 of that cycle the request must have arrived by T2 at the latest. A request that arrives in T3 is accepted in the next suitable T4 or idle cycle; HLDA becomes 1 in the middle of that cycle.

10.1.13Further reading

  • Intel, 8086 16-Bit HMOS Microprocessor data sheet (231455): the numerical values in these notes are taken from the pin descriptions, the timing diagrams and the AC characteristics table.
  • B. B. Brey, The Intel Microprocessors (8th ed.), Chapter 9: the pins of the 8086/8088, the clock generator, bus buffering, bus timing, wait states with READY and minimum/maximum mode, explained with diagrams.
  • D. V. Hall, Microprocessors and Interfacing (2nd ed.): address decoding of an 8086 system, memory and I/O interfacing and maximum-mode design with the 8288, worked through on example boards.
  • K. Shirriff's 8086 articles on righto.com: the bus interface, the queue and the microcode examined at the transistor level through die photographs.

10.1.14References

  1. Intel, 8086 16-Bit HMOS Microprocessor, data sheet (231455).
  2. Intel, data sheets for the 8284A Clock Generator and Driver, the 8288 Bus Controller and the 8282/8283 Octal Latch.
  3. Texas Instruments, data sheets for the SN74LS373 Octal Transparent D-Type Latches and the SN74LS245 Octal Bus Transceivers.
  4. Barry B. Brey, The Intel Microprocessors, 8th ed., Pearson, 2009 (Chapter 9: 8086/8088 hardware specifications).
  5. Douglas V. Hall, Microprocessors and Interfacing: Programming and Hardware, 2nd ed., McGraw-Hill.
  6. Mehmet Bodur, Mikroişlemcilere Giriş: Assembler ile Yazılım ve Arayüz (in Turkish), EMO, 2014.
  7. Ken Shirriff, 8086 die photographs and reverse-engineering articles, righto.com.

Related pages: Chapter 10.1 slides · © Sercan Külcü. All rights reserved.