Chapter 5.1 Interfacing I8086
Chapter 5.1 Interfacing I8086
• Using isolated I/O a microcomputer system, the I/O devices are treated separate from memory. i.e.
I/O locations are isolated from memory system in a separate address space.
• The part of the I/O address space from address 0000H through 00FFH is referred to as Page 0 as
shown in figure (2).
• Supports byte and word I/O ports.
• 64K independent byte-wide I/O ports.
• 32K independent aligned word-wide I/O ports .
• In PC, isolated I/O ports are used for controlling peripheral device .
• 8-bit port address access devices located on system board.
• 16-bit port access serial, parallel ports, video & disk drive.
• i8086 uses M/𝐼𝑂 control signal to select b/n memory and I/O devices.
• User can expand the memory to its full size.
• Data transferred between I/O and microprocessor must be access by IN/OUT instructions.
Figure (8) shows a circuits diagram of a byte-wide input and output ports (8 bit) using isolated I/O for
an 8086 based microcomputer system. From this diagram there is four parts:
Demultiplexing IC:
• Two 74F373 octal latches are used to form a 16-bit address latch. These devices latch the
address A0 through A15 synchronously with the ALE pulse. The latched address outputs are labeled
A0L through A15L.
• Remember that address lines A16 through A19 are not involved in the I/O interface.
• Data bus transceiver buffer in 8086 system is implemented using 74F245 octal bus IC’s, where the
control inputs ‘DIR ’ and ‘𝐺’ҧ is used to control the data flow (An → Bn) or (Bn →An).
Decoder IC:
• A 74F138 (3 Line-to- 8 Line decoder) is used for decoder circuit. Address lines A4L-A15L are applied
to AND gate, output of AND gate and address line A0L provide two of the three enable inputs of
the 74F138 input/output address decoder.
The Latch IC :
• For output circuit we need to store the output data so we use latch, for this purpose 74F374 device
is selected.
• For Figure (8), the gate at the CLK input of 74F374 has its inputs P0 and WR .
The Buffer :
• Buffer is used with input ports. In figure (8) the 74F244 octal buffer is used to implement
• the port. The outputs of the buffer are applied to the data bus for input to the MPU. This buffer has
three-state outputs. For Figure (8), the gate at the G input of 74F244 has its inputs P7 and RD.
collected by eng A4K 2014 11
Fig. (8): A byte-wide input and output ports using Isolated I/P for an 8086 based.
collected by eng A4K 2014 12
INPUT/OUTPUT Device :
• The circuit in figure (8) has 8 LEDs attached to outputs O0 – O7 of output port 0. These LEDs represent
output device.
• Also, in figure (8) there is 8 switches attached to input I0 – I7 of input port 7. These switches
represent input device.
Example 1: For figure (8), what is the I/O address of a. Port 0 (P0) b. Port 7 (P7) Assume all
unused address bit are at logic 0.
Solution:
To enable ports P0–P7→74F138 decoder must be enabled → 𝐺2𝐵 𝐺2𝐴 G1 = 001
G1=1 →output of AND gate=1→A4L– A15L=111111111111
𝐺2𝐵=0 →A0L= 0
𝐺2𝐴=0 →IOM = 0
Example 3:
For the circuit of figure (8), write an instruction sequence that outputs contents of
memory location DS:8000H to output port 0.
Solution: The address of Port P0 =FFF0H. The instruction sequence needed to output the
contents of memory location DS:8000H to output port 0 is:
MOV DX, FFF0H
MOV AL, [8000]
OUT DX, AL
Delay for a short period of time so as to maintain the data written to the LED
MOV CX, FFFFH ; Load delay count of FFFFH
HERE: LOOP HERE ; Time delay loop
The value in bit 7 of AL is complemented to 1 and then a jump is performed to return to the
output operation that writes the data to the output port:
MOV DX, 8000h
XOR AL, 80H ; Complement bit 7 of AL
MOV AL, 00h
JMP ON_OFF ; Repeat to Output the new bit 7
ON_OFF:
OUT DX,AL
MOV CX,FFFFh
HERE:
LOOP HERE
XOR AL,80h
JMP ON_OFF
collected by eng A4K 2014 16
B) MEMORY MAPPED I/O INTERFACING
• I/O devices can be placed in the memory address space of the microcomputer as well as in the
independent I/O address space. In this case, the MPU looks at the I/O port as though it is a storage
location in memory. For this reason, the method is known as memory-mapped I/O. i.e. A device is treated
as memory location and a part of the memory address space is dedicated to I/O devices
• For Example: (E0000H-E0FFFH) → 4096 memory addresses assigned to I/O ports
• E0000H, E0001H, and E0002H correspond to byte wide ports 0,1, and 2
• E0000H and E0001H correspond to word-wide port 0 at address E0000H
• When I/O is configured in this way, instructions that affect data in memory are used instead of the special
input/output instructions. This is an advantage in that many more instructions and addressing modes are
available to perform I/O operations. In addition, I/O transfers can now take place between an I/O port and
an internal register other than just AL or AX. However, this also leads to a disadvantage. That is, the
memory instructions tend to execute slower than those specifically designed for isolated I/O. Therefore, a
memory—mapped I/O routine may take longer to perform than an equivalent program using the
input/output instructions. Uses instructions that transfers data between microprocessor & memory.
Mode selection B
Mode selection A 0 mode 0
00 mode 0 1 mode 1
01 mode 1
1x mode 2
• To know in which mode the interface is working we need to know the value of Control word. Control
word is a part of control register in 8255 which specify an I/O function for each port. This is format of
control word 8255.
collected by eng A4K 2014 23
If the most significant bit of control word or D7 is 1 then 8255 works in I/O mode else, if it’s value is 0 it
works in BSR mode.
A) IO mode -D7=1
I/O Mode – When MSB of the control register is one(1), i8255 works in Input-Output mode.it is further
divided into three categories.
Mode 0 –D6D5 =00 Simple or basic I/O mode:
• Port A, B and C can work either as input function or as output function.
• The outputs are latched but the inputs are not latched. It has interrupt handling capability.
Mode 1 –D6D5=01 Handshake or strobed I/O:
• In this either port A or B can work and port C bits are used to provide handshaking.
• The outputs as well as inputs are latched. It has interrupt handling capability.
• Before actual data transfer there is transmission of signal to match speed of CPU and printer.
• Example: When CPU wants to send data to slow peripheral device like printer, it will send handshaking
signal to printer to tell whether it is ready or not to transfer the data. When printer will be ready it will
send one acknowledgement to CPU then there will be transfer of data through data bus.
Strobe pulse:
A strobe pulse is supplied by one unit to indicate the other unit when the transfer has to occur.
Handshaking pulse:
A control signal is accompanied with each data being transmitted to indicate the presence of data in the
bus.
The receiving unit responds with another control signal to acknowledge receipt of the data.
This type of agreement b/n two independent unit called handshaking.
Busy pulse:
If previous task of data transfer is not accomplished this signal remains active to notify the other device
it is busy
DATA
Other
Device
This mode affects only one bit of port C at a time because, as user set the bit, it remains set until and
unless user changes it. User needs to load the bit pattern in control register to change the bit.
• The 8086 has four special instructions IN, INS, OUT, and OUTS to transfer data through the
input/output ports in I/O mapped I/O system.
• M/IO signal is always low when 8086 is executing these instructions. So M/IO signal is used to
generate separate addresses for, memory and input/output.
• Only 256 (28 ) I/O addresses can be generated when direct addressing method is used.
• By using indirect address method this range can be extended up to 65536 (216 ) addresses.
• Fig. on next slide shows the 8255 Interfacing with 8086 in I/O mapped I/O technique. Here, RD and
WR signals are activated when M/IO signal is low, indicating I/O bus cycle.
• Only lower data bus (D0 — D7) is used as 8255 is 8-bit device. Reset out signal from clock generator
is connected to the Reset signal of the 8255.
• In case of interrupt driven I/O INTR signal (PC3 or PC0) from 8255 is connected to INTR input of
8088.
• In this type of I/O interfacing, the 8086 uses 20 address lines to identify an I/O device; an I/O device is
connected as if it is a memory register.
• The 8086 uses same control signals and instructions to access I/O as those of memory.
• Fig. on thee next slide shows the 8255 Interfacing with 8086 in memory mapped I/O technique.
• Here RD and WR signals are activated when M/IO signal is high, indicating memory bus cycle.
Address lines A0 – A2 are used by 8255 for internal decoding.
• To get absolute address, all remaining address lines (A3 – A19) are used to decode the address for
8255. Other signal connections are same as in I/O mapped I/O.
IO map:
Problem 2 :
A control word is given CW=CDH. Explain the condition of ports of 8255A
Solution:
Programming steps
1. Define the address of each port and control register
2. Write a statement to load the control word
3. Then the body of your program will follow accordingly you will use the port connection
statement with DX then the statement with instruction IN or OUT to get to the input-output
register AL
CODE SEGMENT
MOV DX, COMD ;connecting to the control register
MOV AL, 82H ;loading the control word AL
OUT DX, AL ;loading AL value to the control register through DX
START:
MOV DX, PORTB
IN AL, DX ;receiving the input from portB
;so you can put any logic any where but according to the steps
CODE ENDS
END
collected by eng A4K 2014 36
Problem 1: Configure Port in Mode 2, Port B as O/P in mode 1
Control words including the don’t care will take different value: 1100 0100/1100 0101/1100
1100/1100 1101/1101 0100/1101 0101/1101 1100/1101 1101/1110 0100/1110 0101/1110
1100/1110 1101/1111 0100/1111 0101/1111 1100/1111 1101
Equivalently in hex: C4H/C5H/D4H/D5H/DCH/DDH/E4H/E5H/ECH/EDH/F4H/F5H/FCH/FDH
Problem 2: Write an8086 assembly language procedure to red an Ascii character from keyboarded via
port A of n 8255 PPI when Port C bit is strobed low assume base dress of 20h
7-seg DISPLAY
U3
AD[0..15] AD0 34 4
D0 PA0
AD1 33 3
U2 AD2 32
D1 PA1
2
AD0 D2 PA2
3 2 AD3 31 1
D0 Q0 D3 PA3
AD1 4 5 AD4 30 40
D1 Q1 D4 PA4
AD2 7 6 AD5 29 39
D2 Q2 D5 PA5
AD3 8 9 AD6 28 38
D3 Q3 D6 PA6
AD4 13 12 AD7
27 37
D4 Q4 D7 PA7
AD5 14 15
D5 Q5
AD6 17 16 5 18
D6 Q6 RD PB0
AD[0..15]
AD7 18 19 36 19
D7 Q7 WR PB1
9 20
A0 PB2
1 8 21
OE A1 PB3
11 35 22
LE RESET PB4
23
PB5
74HC373 6 24
U1 CS PB6
25
21 PB7
RESET AD[0..15]
22
READY A[16..19] 14
24 PC0
INTA/QS1 15
18 25 PC1
INTR ALE/QS0 16
31 34 PC2
HOLD/GT1 BHE 17
30 27 PC3
HLDA/GT0 DT/R/S1 13
23 26 PC4
TEST DEN/S2 12
17 32 PC5
NMI RD 11
33 29 PC6
MN/MX WR/LOCK 10
19 28 PC7
CLK M/IO/S0
8086
8255A
PUSH BUTTONS
i8086 microporcessor 8255A PPI
collected by eng A4K 2014 47
collected by eng A4K 2014 48
8237 DMA Controller interface technique
• DMA is an input output technique used for high speed data transfer
• Data transfer between system memory and floppy disk
• The direct memory access DMA interface of the 8086 minimum mode consist of the HOLD and HLDA
signals.
• When an external device wants to take control of the system bus, it signals to the 8086 by switching
HOLD to the logic 1 level. At the completion of the current bus cycle, the 8086 enters the hold state.
• The 8237 works in two modes i.e., master and slave modes.
• In slave mode, the 8237 functions as an input/output device. In this mode the system buses arc
controlled by microprocessor and hence the microprocessor is connected to the system bus.
• In master mode 8237 becomes the bus master and hence the microprocessor is isolated from the system
bus. This isolation is done by AEN signal.
• In minimum configuration, 8237 DMA controller is used to transfer the data. The peripheral chips are
interface as normal 10 ports. Figure shows the interfacing of DMA controller with 8086.
• In minimum mode the HOLD and HLDA signals are used to bus arbitration and in maximum mode
configuration RQ_0/GT_0; and RQ_1/GT_1.
The 8237 is in the idle cycle if there is no pending request or the 8237 is waiting for a request from one of
the DMA channels. Once a channel requests a DMA service, the 8237 sends the HOLD request to the CPU
using its HRQ pin. If the CPU acknowledges the hold request on HLDA, the 8237 enters an active cycle. In
the active cycle, the actual data transfer takes place in one of the following transfer modes as is
programmed.
1. Single Transfer Mode: In this mode, the device transfers only one byte per request.
• The word count is decremented and the address is decremented or incremented (depending on
programming) after each such transfer.
• The Terminal Count (TC) state is reached when the count becomes zero.
• For each transfer the DREQ must be active until the DACK is activated, in order to get recognized.
After TC the bus will be relinquished for the CPU.
• For a new DREQ to 8237 it will again activate the HRQ signal to the CPU and the HLDA signal from
the CPU will push the 8237 again into the single transfer mode.
• This mode is also called as 'cycle stealing'.
2. Block Transfer Mode: In this mode, the 8237 is activated by DREQ to continue the transfer until a TC is
reached, i.e. a block of data is transferred.
• The transfer cycle may be terminated due to EOP (either internal or external) which forces
Terminal Count (TC).
• The DREO needs to be activated only till the DACK signal is activated by the DMA controller.
Auto-initialization may be programmed in this mode.
collected by eng A4K 2014 52
3. Demand Transfer Mode: In this mode, the device continues transfers until a TC is reached or an
external EOP is detected or the DREQ signal goes inactive. Thus a transfer may exhaust the capacity
of data transfer of an I/O device.
• After the I/O device is able to catch up the service may be re-established activating the DREQ
signal again. Only the EOP generated by TC or external EOP can cause the auto-initialization, and
only if it is programmed for.
4. Cascade Mode: In this mode, more than one 8237 can be connected together to provide more than
four DMA channels.
• The HRQ and HLDA signals from additional 8237s are connected with DREQ and DACK pins of a
channel of the host 8237 respectively.
• The priorities of the DMA requests may be preserved at each level.
• The first device is only used for prioritizing the additional devices (slave 8237s), and it does not
generate any address or control signal of its own.
• The host 8237 responds to DREQ generated by slaves and generates the DACK and the HRQ
signals to coordinate all the slaves. All other outputs of the host 8237 are disabled.
5. Memory to memory Transfer: To perform the transfer of a block of data from one set of memory
address to another one, this transfer mode is used.
• Programming the corresponding mode bit in the command word, sets the channel 0 and I to
operate as source and destination channels, respectively.
• The transfer is initialized by setting the DREQ0 using software commands.
• The 8237 sends HRQ (Hold Request) signal to the CPU as usual and when the HLDA signal is
activated by the CPU. the device starts operating in block transfer mode to read the data from
memory.
collected by eng A4K 2014 53
• The channel 0 current address register acts as a source pointer.
• The byte read from the memory is stored in an internal temporary register of 8237.
• The channel 1 current address register acts as a destination pointer to write the data from the
temporary register to the destination memory location.
• The pointers are automatically incremented or decremented, depending upon the programming.
• The channel 1 word count register is used as a counter and is decremented after each transfer.
• When it reaches zero, a TC is generated, causing EOP to terminate the service.
• The 8237 also responds to external EOP signals to terminate the service.
• This feature may be used to scan a block of data for a byte. When a match is found the process may
be terminated using the external EOP.
• Under all these transfer modes, the 8237 carries out three basic transfers namely, write transfer, read
transfer and verify transfer.
• In write transfer, the 8237 reads from an I/O device and writes to memory under the control of IOR
and MEMW signals.
• In read transfer, the 8237 reads from memory and writes to an I/O device by activating the MEMR and
IOW signals.
• In verify transfers, the 8237 works in the same way as the read or write transfer but does not generate
any control signal.
I/O Interfacing
1. All I/O peripherals that are covered in this course are 8-bit so they have to be interfaced only to D0-D7 or
D8-D15 - not to both the buses.
2. If I/O device is connected to D0-D7 then only even addresses must be assigned.
3. If I/O device is connected to D8-D15 then only odd addresses must be assigned.
4. When using fixed addressing - then it is suffice to use Address lines A0-A7 for decoding and addressing.
5. When using variable addressing - then you need to use Address lines A0-A15 for decoding and
addressing.
6. With I/O mapped I/O IOR and IOW should be used for read and write.
7. If memory mapped I/O use MEMR and MEMW.
8. In case of memory mapped I/O you need to ensure that there is no clash between memory and I/O
address - for eg. address 01000H should not be assigned to both memory and I/O devices.
collected by eng A4K 2014 55
8255 Interfacing
1. The ports of 8255 in an un-programmed state are input ports- this because if they are output in
unconfigured state and any input device is connected to it - the input device will also be generating an
output on the port lines and 8255 will also be producing an output. When two outputs are tied
together it results in the destruction one of /both the devices.
2. The output pins of 8255 cannot be used for powering-up devices - as they will not be able to supply
the required driving current.
3. When connecting motors/lamps/speakers etc.. to 8255 - check the current rating of 8255 and the
devices - in the case where 8255 is not able to supply the required driving current make use of
amplifiers such as 7406 (inverting) and 7407(non-inverting amplifiers. In the case of large current
requirements make use of transistors in a Darlington Pair configuration. Click on link below for a brief
description of Darlington pair transistors. Darlington Pair.
4. When interfacing Dc motors to 8255 - select appropriate H-Bridges according to motor specification.
5. H-bridges allows DC motors to run in both directions - you can look at this blog post to understand
how H-Bridges work. H-Bridge operation
6. Port A and Port B can be used only as 8-bit ports - so all pins of Port A/Port B have to be input or
output.
7. Port C can be used as 8-bit port, 4-bit port or as individual port bits in BSR.
8. When connecting AC powered devices to 8255 make use of a relay.
9. When Port A/Port B are programmed in Mode 1/Mode 2 Port C cannot function as normal I/O port.
8259 Interfacing
1. 8259 has only two addressable - so the order in which the command words are written are important.
2. OCWs are always written after the ICWs.
3. SP/EN in case of single 8259 - must always be connected to Vcc.
4. Unless you are sure about how long an interrupt request will be held high - do not use level triggering.
5. Edge triggering is preferred.
6. Since 8086 is used Do of ICW1 will always be set and ICW4 will always have to be provided.
7. It is preferred that AEOI is not used as this may violate the interrupt priorities.
8. Do not use reserved vector numbers - it is always safe to start with vector 40H.
9. If you have not used AEOI - make sure that a non-specific EOI is given at the end of the ISR before IRET
statement.
10. Make sure that IVT is initialized before using interrupts.
1. As a coprocessor (8087) is connected to 8086, 8086 operates in maximum mode. Thus the MN/𝑀𝑋 is
grounded.
2. 8284 provides the common CLK, RESET and READY signals. 8282 are used to latch the address.
8286 are used as data trans-receivers. 8288 generates control signals using 𝑆2 , 𝑆ഥ1 and 𝑆0 as input
from the currently active processor. 8259 PIC is used to accept the interrupt from 8087 and send it to
the microprocessor.
3. This interface is also called as coprocessor configuration. Here 8086 is called as the host and 8087 as
coprocessor as it cannot operate all by itself.
4. We write a homogeneous program which contains both 8086 as well as 8087 instructions.
5. Only 8086 can fetch instructions but these instructions also enter 8087. 8087 treats 8086
instructions as NOP.
6. ESC is used as a prefix for 8087 instructions. When as instruction with ESC prefix (5 MSB bits as
11011) is encountered, 8087 is activated.
7. The ESC instruction is decoded by both 8086 and 8087.
8. If the 8087 instruction has only an opcode (no operands) then 8087 will start execution and 8086 will
immediately move its next instruction.
9. But if the instruction requires a memory operand, then 8086 will have to fetch the first word of the
operand as 8087 cannot calculate the physical address. This word will be captured by 8087. Now the
remaining words (for a large operand) can be fetched by 8087 by simply incrementing the address of
the first word. Thus 8087 need help from 8086.
10. Once 8087 gets its operand, it begins processing by making the BUSY output high. This BUSY
output is connected to the TEST input of the microprocessor. Now 8087 execute its instruction and
8086 moves ahead with its next instruction. Hence multiprocessing takes place.
11. During execution, if 8087 needs to read/ write more words from the memory, then it does so by
stealing bus cycles from the microprocessor in the following manner. The 𝑅𝑄 / 𝐺𝑇0 of 8087 is
connected to 𝑅𝑄 / 𝐺𝑇0 of the microprocessor. 8087 gives an active low request pulse. 8086
completes the current bus cycle and gives the grant pulse and enters the hold state. 8087 uses the
shared system bus to perform the data transfer with the memory. 8087 gives the release pulse and
returns the system bus back to the microprocessor.
12. If 8086 requires the result of the 8087 operation, it first executes the WAIT instruction. WAIT makes
the microprocessor check the TEST pin. If the TEST pin is high (8087 is BUSY), then the
microprocessor enters WAIT state. It comes out of it only when TEST is low (8087 has finished its
execution). Thus 8086 get the correct result of an 8087 operation.
13. During the execution if an exception occurs, which is unmasked, 8087 interrupts microprocessor
using the INT output pin through the PIC 8259.
14. The QS0 and QS1 lines are used by 8087 to monitor the queue of 8086. 8087 needs to know when
8086 will decode the ESC instruction so it synchronizes its queue with 8086 using QS0 and QS1 as
follows:
This is the complete inter-processor communication between 8086 and 8087 to form a
homogeneous system.
collected by eng A4K 2014 61
Below is another example of i8087 assembly code that calculates the volume of a cylinder (volume = π *
radius² * height). This example demonstrates more FPU stack operations and data conversions:
DATA SEGMENT
radius dd 3.0 ; Radius (32-bit float)
height dd 10.0 ; Height (32-bit float)
volume dd 0.0 ; Result (32-bit float)
pi dt 3.14159265358979323846 ; 80-bit extended precision Pi
CODE SEGMENT
START:
FINIT ; INITIALIZE THE FPU
; LOAD RADIUS INTO ST0 AND SQUARE IT
FLD DWORD [RADIUS] ; ST0 = 3.0
FMUL ST0, ST0 ; ST0 = 3.0^2 = 9.0
; MULTIPLY BY PI (ST0 = 9.0 * PI)
FLD TWORD [PI] ; ST0 = PI, ST1 = 9.0
FMULP ST1, ST0 ; ST0 = 9.0 * PI ≈ 28.2743
; MULTIPLY BY HEIGHT (ST0 = 28.2743 * 10.0)
FLD DWORD [HEIGHT] ; ST0 = 10.0, ST1 = 28.2743
FMULP ST1, ST0 ; ST0 = 28.2743 * 10.0 ≈ 282.743
; STORE RESULT AND POP THE STACK
FSTP DWORD [VOLUME] ; [VOLUME] = 282.743
; EXIT PROGRAM (LINUX SYSCALL EXAMPLE)
MOV EAX, 1 ; SYS_EXIT
XOR EBX, EBX ; EXIT CODE 0
INT 0X80