mp mod 3
mp mod 3
MODULE – III
Interrupt mechanism of x86 & Interfacing of
chips
Interrupts
The meaning of ‘interrupts’ is to break the sequence of operation. While the CPU is executing a
program, on ‘interrupt’ breaks the normal sequence of execution of instructions, diverts its execution to some
other program called Interrupt Service Routine (ISR) or Interrupt Service Procedure (ISP).After executing
ISR , the control is transferred back again to the main program. Interrupt processing is an alternative to polling.
ISR is a program that tells the processor what to do when the interrupt occurs. At the end of the ISR the
last instruction should be IRET. After the execution of ISR, control returns back to the main routine where it
was interrupted.
Need for Interrupt: Interrupts are particularly useful when interfacing I/O devices that provide or require data
at relatively low data transfer rate.
Whenever a number of devices interrupt a CPU at a time, and if the processor is able to handle them
properly, it is said to have multiple interrupt processing capability. There are two interrupt pins in 8086. NMI
and INTR
Interrupts of 8086
Types of Interrupts:
INTR
INTR is a maskable hardware interrupt. The interrupt can be enabled/disabled using STI/CLI
instructions or using more complicated method of updating the FLAG register with the help of the POPF
instruction.
When an interrupt occurs, the processor stores FLAGS register into stack, disables further interrupts,
fetches from the bus one byte representing interrupt type, and jumps to interrupt processing routine address of
which is stored in location 4 * <interrupt type>. Interrupt processing routine should return with the IRET
instruction.
The INTR interrupt is activated by an I/O port. If the interrupt is enabled and NMI is disabled, then the
microprocessor first completes the current execution and sends ‘0’ on INTA pin twice. The first ‘0’ means
INTA informs the external device to get ready and during the second ‘0’ the microprocessor receives the 8 bit,
say X, from the programmable interrupt controller.
NMI
NMI is a non-maskable interrupt. Interrupt is processed in the same way as the INTR interrupt. Interrupt
type of the NMI is 2, i.e. the address of the NMI processing routine is stored in location 0008h. This interrupt
has higher priority than the maskable interrupt.
SOFTWARE INTERRUPTS
Interrupts are generated by a software instruction and operate similarly to a jump or branch instruction.
256 interrupts are there.
INT n is invoked as software interrupts - n is the type Number in the range 0 to 255(00 to FF).
They are divided into three groups
1. Type 0 to Type4 (Dedicated Interrupts)
TYPE 0 interrupt represents division by zero
TYPE 1 interrupt represents single-step execution during the debugging of a program. –
TYPE 2 interrupt represents non-maskable NMI interrupt. –
TYPE 3 interrupt represents break-point interrupt. –
TYPE 4 interrupt represents overflow interrupt.
2. Type 5 to 31(Not used by 8086, reserved for higher processor like 80286,80386….
3. Type 32-255(Available for user) - User defined interrupts
MGM Polytechnic College, Kilimanoor (CT Department) Page 61
MICROPROCESSORS AND INTERFACING (5131)
5. Both the interrupt (IF) and (TF) flags are cleared. This disables the INTR pin and the trap or single-step
feature.
6. The contents of the code segment register (CS) are pushed onto the Stack.
7. The contents of the instruction pointer (IP) are pushed onto the Stack.
8. The interrupt vector contents are fetched, from (4 x N) and then placed into the IP and from (4 x N +2) into
the CS so that the next instruction executes at the interrupt service procedure addressed by the interrupt vector.
9. While returning from the interrupt-service routine by the Interrupt Return (IRET) instruction, the IP, CS and
Flag registers are popped from the Stack and return to their state prior to the interrupt.
Iterrupt Priority
As far as the Interrupt Priority in 8086 are concerned, software interrupts (All interrupts except single step, NMI
and INTR interrupts) have the highest priority, followed by NMI followed by INTR. Single step has the least
priority.
The interrupt flag is automatically cleared as part of the response of an 8086 to an interrupt. This prevents a
signal on the INTR input from interrupting a higher priority interrupt service routine. The 8086 allows NMI
input to interrupt higher priority interrupt, for example suppose that a rising edge signal arrives at the NMI input
while the 8086 is executing a DIV instruction, and that the division operation produces a divide error. Since the
8086 checks for internal interrupts before it checks for an NMI interrupt, the 8086 will push the flags on the
stack, clear TF and IF, push the return address on the stack, and go to the start of the divide error service
routine.
The 8086 will then do an NMI interrupt response and execute non-maskable interrupt service routine. After
completion of NMI service routine an 8086 will return to the divide error routine. It will execute divide error
routine and then it will return to the main program (refer Fig. 9.4).
Interface is the path for communication between two components. Interfacing is of two types, memory
interfacing and I/O interfacing.
To communicate with the outside world microcomputers use peripherals (I/O devices). Commonly
used peripherals are: keyboard, mouse, printer, etc.
Peripherals are connected to the microcomputer through electronic circuits known as interfacing circuits.
8259 PIC
The 8259 is known as the Programmable Interrupt Controller (PIC) microprocessor.
Programmable interrupt controllers are used to enhance the number of interrupts of a microprocessor. 8259 is a
programmable interrupt controller which shows compatibility with 8085 microprocessor.
It is also known as a priority interrupt controller and was designed by Intel to increase the interrupt
handling ability of the microprocessor. An 8259 PIC never services an interrupt; it simply forwards the interrupt
to the processor for the execution of interrupt service routine.
Architecture of 8259
The figure below shows the architectural representation of 8259 programmable interrupt controller:
Control Logic:
This unit is the heart of the architecture of 8259. It controls the overall operation of the system by
sending the INTR signal to the processor whenever an interrupt request is generated.
Also, it receives INTA signal by the processor when microprocessor demands for the address of the
interrupt service routine. The control logic is responsible for sending the address of the desired interrupt service
routine through the data bus.
Priority Resolver:
This logic unit decides that among the entire interrupt request present in the IRR which holds the highest
priority and needs to be executed first.
Suppose at the time of servicing an interrupt, another incoming interrupt request gets generated then that
request will be ignored as the one in-service is holding the highest priority.
But in case the incoming request has greater priority than the one which is being in current execution
then that respective bit will be set in ISR and INTR signal is sent to the microprocessor.
This simply means that only the interrupt holding the highest priority will be forwarded by the 8259 to
the processor.
In-service register:
Here the name of the unit is itself indicating the operation performed by it. This register unit stores the
interrupts which are currently being executed by the processor.
The priority resolver sets each bit of ISR and after getting interrupt word command by the processor, the
bits get reset. As the processor holds the ability to directly read the status of in-service register.
Cascade buffer/comparator:
As we have already discussed that by cascading multiple 8259, the number of interrupts handled by 8259
can be expanded up to 64. The unit allows the comparison of IDs of different 8259s cascaded together.
It permits the operation of the system in two modes: master mode and slave mode.
In the master mode of operation, it acts as a cascaded buffer. Whereas in slave mode, this unit acts as a
comparator.
Among the various cascaded 8259, one 8259 directly handles the interrupts by forming a connection
with the processor and it is known to be master 8259. While the other 8259s that interrupts the master 8259 are
known as slave 8259.
Each of the 8259s can be separately programmed as all of them holds a specific address. The cascading
pins of the master 8259, CAS0, CAS1 and CAS2 forms connection with the corresponding pins of slave 8259s.
For the slave devices, these pins act as input pins while for a master device these acts as output pins. An active-
low signal at SP/EN for a device shows that it is operating in slave mode.
The processor issues some words termed as command words to the ports so as to configure the 8259
better. There are several command words often classified as initialization command words and operation
command words.
8259 has four initialization command words namely ICW1, ICW2, ICW3, and ICW4 and three operation
command words namely as OCW1, OCW2, and OCW3.
Initialization command words(ICW) :
ICW is given during the initialization of 8259 i.e. before its start functioning.
ICW1 and ICW2 commands are compulsory for initialization.
ICW3 command is given during a cascaded configuration.
8255A – PPI
8255A - Programmable Peripheral Interface(PPI)
Intel 8255 is a peripheral interface (PPI) chip which is programmable. It is used for the connection of peripheral
devices and interfacing. We call Peripheral device also as Input Output device. We use Input Output ports for
the connection of Input Output devices. Hence 8255 is a programmable Input Output port chip.
It is a 40 pin chip available for dual line packaging. Power supply of +5 Volt DC is needed for its
working. It consists of two programmable Input Output ports having of size 8 bits and two programmable Input
Output ports of size 4 bits. We call them as Port A, Port B, Port C upper, and Port C lower, respectively. These
pins source 1 mA of current at 1.5V, when they are programmed to work as the Output pins.
Features of 8255A
The prominent features of 8255A are as follows −
It consists of 3 8-bit IO ports i.e. PA, PB, and PC.
Address/data bus must be externally demux'd.
It is TTL compatible.
It has improved DC driving capability.
CS
It stands for Chip Select. A LOW on this input selects the chip and enables the communication between the
8255A and the CPU. It is connected to the decoded address, and A0 & A1 are connected to the microprocessor
address lines.
Ports of 8255A
8255A has three ports, i.e., PORT A, PORT B, and PORT C.
Port A contains one 8-bit output latch/buffer and one 8-bit input buffer.
Port B is similar to PORT A.
Port C can be split into two parts, i.e. PORT C lower (PC0-PC3) and PORT C upper (PC7-PC4) by the
control word.
These three ports are further divided into two groups, i.e. Group A includes PORT A and upper PORT
C. Group B includes PORT B and lower PORT C. These two groups can be programmed in three different
modes, i.e. the first mode is named as mode 0, the second mode is named as Mode 1 and the third mode is
named as Mode 2.
Operating Modes
8255A has three different operating modes −
Mode 0 − In this mode, Port A and B is used as two 8-bit ports and Port C as two 4-bit ports. Each port
can be programmed in either input mode or output mode where outputs are latched and inputs are not
latched. Ports do not have interrupt capability.
Mode 1 − In this mode, Port A and B is used as 8-bit I/O ports. They can be configured as either input or
output ports. Each port uses three lines from port C as handshake signals. Inputs and outputs are latched.
Mode 2 − In this mode, Port A can be configured as the bidirectional port and Port B either in Mode 0 or
Mode 1. Port A uses five signals from Port C as handshake signals for data transfer. The remaining three
signals from Port C can be used either as simple I/O or as handshake for port B.
Scan Counter
It has two modes i.e. Encoded mode and Decoded mode. In the encoded mode, the counter provides the binary
count that is to be externally decoded to provide the scan lines for the keyboard and display.
In the decoded scan mode, the counter internally decodes the least significant 2 bits and provides a
decoded 1 out of 4 scan on SL0-SL3.
INPUT MODES
The input which is provided by the keyboard to the system specifies the input mode. This mode is classified into
the following categories:
1. Scanned Keyboard Mode: In this operating mode, the key matrix is interfaced with either encoded or
decoded scan. In encoded scan, 8*8 keyboard is interfaced while in the decoded scan, 4*8 keyboard is
interfaced. The keycodes are stored in the FIFO RAM.
2. Scanned Sensor Matrix: This helps in interfacing the sensor array with 8279 by making use of an
encoder or decoder scan. Similar to scanner keyboard mode, 8*8 sensor matrix for encoder scan and 4*8
sensor matrix interfacing for decoder scan.
3. Strobed Input: This mode of operation, if control is not offered by the processor and the control line
shows low signal then the data present on the return lines is stored in FIFO RAM byte by byte.
OUTPUT MODES
This mode is also known as a display mode. It is further classified into two modes. This mode helps in selecting
the display options.
1. Display Scan: The 8279 generates 8 or 16 characters multiplexed displays that are organized in either
dual 4-bit or single 8-bit display units.
2. Display Entry: The data which gets displayed can be either displayed starting from either the right side
or left side.
DISPLAY MODES
This mode is associated with data display and has two further classifications.
1. Left Entry Mode: It is also known as typewriter mode. In this, the first type of character is present at
the left-most position while further incoming characters appear successively towards the right. This
means data begins to appear from the left side of the display unit. So, the bit value at address 0 in the
display RAM will appear at the left-most position whereas the bit value at address 15 will appear at the
right-most position.
2. Right entry Mode: This mode is also known as calculator mode. This is so because in the calculator the
first entered character appears at the rightmost position and then successively when a new character has
entered the position of the former one is shifted towards the left. Thus, in this mode, the first entry will
appear at the rightmost position but as soon as a new entry is made then the previous one will get shifted
towards the left by one and the present entry will take the rightmost position.