CST307 - M3 Ktunotes - in
CST307 - M3 Ktunotes - in
CST307 - M3 Ktunotes - in
Stack structure of 8086, programming using stack- Interrupts - Types of Interrupts and
Interrupt Service Routine- Handling Interrupts in 8086- Interrupt programming -
Programmable Interrupt Controller - 8259, Architecture (Just mention the control word, no
need to memorize the control word)- Interfacing Memory with 8086.
Interrupts
Definition: 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). After executing ISR, the control is transferred back again to the main program.
Interrupt processing is an alternative to polling.
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
Need for Interrupt: Interrupts are particularly useful when interfacing I/O devices that
provide or require data at relatively low data transfer rate.
NMI
It is a single non-maskable interrupt pin (NMI) having higher priority. When this interrupt is
activated,
these actions take place −
• Completes the current instruction that is in progress.
• Pushes the Flag register values on to the stack.
INTR
• The INTR is a maskable interrupt pin. It can be accepted (enable) or rejected (masked).
• The microprocessor enabled the interrupt using set interrupt flag instruction. It should
disable using clear
• interrupt Flag instruction.
• These actions are taken by the microprocessor −
• First completes the current instruction.
• Activates INTA output and receives the interrupt type, say X.
• Flag register value, CS value of the return address and IP value of the return address
are pushed on to the stack.
• IP value is loaded from the contents of word location X × 4
• CS is loaded from the contents of the next word location.
• Interrupt flag and trap flag is reset to 0
Internal (or) Software Interrupts are generated by a software instruction and operate
similarly to a jump or branch instruction.
External (or) Hardware Interrupts are caused by an external hardware module.
HARDWARE INTERRUPTS
Hardware interrupts are generated by hardware devices when something unusual happens; this
could be a
key-press or a mouse move or any other action.
It can be divided into two
1. Maskable 2. Non maskable
Maskable Interrupts:
There are some interrupts which can be masked (disabled)or enabled by the processor.
Non-Maskable Interrupts:
There are some interrupts which cannot be masked out or ignored by the processor. These are
associated
with high priority tasks which cannot be ignored (like memory parity or bus faults).
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 no in the range 0 to 255(00 to FF)
Interrupts are divided into three groups
Type 0 to Type4 (Dedicated Interrupts)
- TYPE 0 interrupt represents division by zero situation.
- TYPE 1 interrupt represents single-step execution during the debugging of a program.
For every interrupt, there must be an interrupt service routine (ISR), or interrupt handler. When
an interrupt is invoked, the microprocessor runs the interrupt service routine. For every
interrupt, there is a fixed location in memory that holds the address of its ISR. The group of
memory locations set aside to hold the addresses of ISRs is called the interrupt vector table.
2nd INTA pulse – The interrupting device sends the vector number ‘N’ to the microprocessor.
o Now microprocessor multiplies N x 4 and goes to the corresponding location in the IVT to
obtain the ISR address. INTR is a mask-able interrupt.
o It is masked by making IF = 0 by software through CLI instruction.
o It is unmasked by making IF = 1 by software through STI instruction.
Necessity of 8259A
In a system, microprocessor may need to perform the following tasks in an efficient way using
interrupt:
Count interrupts from a timer to produce a real time clock of seconds, minutes and hours.
Detect several emergency signals like power failure etc on an interrupt basis.
Each of these interrupt applications requires a separate interrupt pin. But, the 8086 has
only two interrupt inputs: NMI and INTR. If we use NMI for a power failure interrupt, this
leaves only one interrupt input for all other applications. The solution is to use an external
device called a priority interrupt controller (PIC) such as Intel 8259A.
Internal 8259 Block Diagram includes eight blocks: data bus buffer, read/write logic, control
logic, three registers (IRR, ISR and IMR), priority resolver, and cascade buffer.
It accepts requests from the peripheral equipment, determines which of the incoming
requests is of the highest importance (priority), ascertains whether the incoming request has a
higher priority value than the level currently being serviced and issues an interrupt to the CPU
based on this determination.
Each peripheral device or structure usually has a special program or, routine that is associated
with its specific functional or operational requirements; that is referred to as a service routine
or service procedure.
The 8259A PIC, after issuing an interrupt to the CPU, must somehow input information
(interrupt vector number) into the CPU that can point the program counter to the service
procedure associated with the requesting device.
The 8259A PIC adds eight vectored priority encoded interrupts to the microprocessor.
This controller can be expanded without additional hardware, to accept up to 64 interrupt
requests. This require a master 8259A and eight 8259A slaves.
The data bus buffer allows the 8085 to send control words to the 8259A and read a status word
from the 8259 Block Diagram. The 8-bit data bus buffer also allows the 8259A to send interrupt
opcode and address of the interrupt service subroutine to the 8085.
This section generates control signals necessary for cascade operations. It also generates
Buffer-Enable signals. As stated earlier, the 8259 Block Diagram can be cascaded with other
8259s in order to expand the interrupt handling capacity to sixty-four levels. In such a case, the
former is called a master, and the latter are called slaves. The 8259 can be set up as a master
or a slave by the SP/EN pin.
CAS0— CAS2
For a master 8259, the CAS0-CAS2 pins are output pins, and for slave 8259, these are input
pins. When the 8259 is a master (that is, when it accepts interrupt requests from other 8259s),
the CALL opcode is generated by the Master in response to the first INTA. The vector address
must be released by the slave 8259. The master sends an identification code of three-bits to
select one out of the eight possible slave 8259s on the CAS0-CAS2 lines. The slave 8259s accept
these three signals as inputs (on their CAS0 – CAS2 pins) and compare the code sent by the
master with the codes assigned to them during initialization. The slave thus selected (which
had originally placed an interrupt request to the master 8259) then puts the address of the
interrupt service routine during the second and third INTA pulses from the CPU.
The cascade lines (CAS2-CAS0) are used as outputs from the master to the slaves for cascading
multiple 8159As in a system. The master outputs a 3-bit slave identification number on these
lines. Each slave in a system is assigned a 3-bit ID as part of its initialization. Sending this 3-
bit ID number enables the slave.
The SP/EN signal is tied high for the master. However, it is grounded for the slave.
In large systems where buffers are used to drive the data bus, the data sent by the 8259 in
response to INTA cannot be accessed by the CPU (due to the data bus buffer being disabled).
If an 8259 is used in the buffered mode (buffered or non-buffered modes of operation can be
specified at the time of initializing the 8259), the SP/EN pin is used as an output which can be
used to enable the system data bus buffer whenever the data bus outputs of 8259 are enabled
(i.e. when it is ready to send data).
Thus, in non-buffered mode, the SP/EN pin of an 8259 is used to specify whether the 8259 is
to operate as a master or as a slave, and in the buffered mode, the SP/EN pin is used as an
output to enable the data bus buffer of the system.
INT Pin:
The interrupt output (INT) pin of 8259A is connected to the INTR pin on the microprocessor
(8086) when there is only one 8259A in the system. In a system with master and slaves, only
master’s INT pin is connected to 8086. The slave’s INT pins are connected to different IR pins
of the master.
Read/Write Logic:
The RD and WR inputs control the data flow on the data bus when the device is selected by
asserting its chip select (CS) input low.
Control Logic:
This block has an input and an output line. If the 8259A is properly enabled, the interrupt
request will cause the 8259A to assert its INT output pin high. If this pin is connected to the
INTR pin of an 8085 and if the 8085 Interrupt Enable (IE) flag is set, then this high signal will
cause the 8085 to respond INTR as explained earlier.
ICWs are used to set up the proper conditions and specify RST vector address.
The OCWs are used to perform functions such as masking interrupts, setting up status-read
operations etc.
Step-1: The IRR of 8259A stores the request.
Step-2: The priority resolver checks 3 registers-
* The IRR for interrupt requests. * IMR for masking bits and * The ISR for interrupt request
being served. It resolves the priority and sets the INT high when appropriate.
Step-3: The MPU acknowledges the interrupt by sending signals in 𝐼𝑁𝑇𝐴.
Step-4: After the 𝐼𝑁𝑇𝐴 is received, the appropriate priority bit in the ISR is set to indicate
which interrupt level is being served and the corresponding bit in the IRR is reset to indicate
that the request for the CALL instruction is placed on the data bus.
Step-5: When MPU decodes the CALL instruction, it places two more 𝐼𝑁𝑇𝐴 signals on the
data bus.
Step-6: When the 8259A receives the second 𝐼𝑁𝑇𝐴, it places the low-order byte of the CALL
address on the data bus. At the 3rd 𝐼𝑁𝑇𝐴, it places the high order byte on the data bus. The
CALL address is the vector memory location for the interrupt, this address is placed in the
control register during the initialization.
Step-7: During the 3rd 𝐼𝑁𝑇𝐴 pulse, the ISR bit is reset either automatically (Automatic-End-
of-Interrupt-AEOI) or by a command word that must be issued at the end of the service routine
(End of Interrupt-EOI). This option is determined by the initialization command word (ICW).
Step-8: The program sequence is transferred to the memory location specified by the CALL
instruction.
Semiconductor memories are of two types, viz. RAM (Random Access Memory) and
ROM (Read Only Memory). The semiconductor RAMs are of broadly two types-static RAM
and dynamic RAM. The semiconductor memories are organized as two-dimensional arrays of
memory locations. For example, 4Kx8 or 4K byte memory contains 4096 locations, where each
location contains 8-bit data and only one of the 4096 locations can be selected at a time.
Problem 1
Interface two 4Kx8 EPROM and two 4Kx8 RAM chips with 8086. Select suitable maps.
Memory Map Table
Total 8K bytes of EPROM need 13 address lines A0-A12 (since z13 = 8K).
Address lines A13 - A19 are used for decoding to generate the chip select.
The ___ signal goes low when a transfer is at odd address or higher byte of data is to be
accessed.
Let us assume that the latched address, ___ and demultiplexed data lines are readily available
for interfacing.
It is better not to use a decoder to implement the above map because it is not continuous, i.e.
there is some unused address space between the last RAM address (0FFFF H) and the first
EPROM address (F8000 H). Hence the logic is implemented using logic gates.
INTERRUPTS
An INTERRUPT is a condition that causes the microprocessor to temporarily work on a different task and
then return to its previous task. Interrupt is an event or signal that request to attention of CPU. Whenever an
interrupt occurs the processor completes the execution of the current instruction and starts the execution of
an Interrupt Service Routine (ISR) or Interrupt Handler. ISR is a program that tells the processor what to do
when the interrupt occurs. After the execution of ISR, control returns back to the main routine where it was
interrupted.
INTERRUPT PINS
There are two interrupt pins in 8086. NMI and INTR
NMI: It is a single non-maskable interrupt pin (NMI) having higher priority. When this interrupt is
activated, these actions take place −
• Completes the current instruction that is in progress.
• Pushes the Flag register values on to the stack.
• Pushes the CS (code segment) value and IP (instruction pointer) value of the return
In INTERRUPT method, whenever any device needs service from microprocessor, the device notifies to
processor by sending signal called interrupt. Upon receiving an interrupt signal, the microprocessor holds
whatever it is doing and serves the corresponding device. The program associated with the interrupt is called
the interrupt service routine (ISR) or interrupt handler.
SOURCES OF INTERRUPTS
TYPES OF INTERRUPTS
In general, there are two types of Interrupts:
Internal (or) Software Interrupts are generated by a software instruction and operates similarly to a
jump or branch instruction.
External (or) Hardware Interrupts are caused by an external hardware module
HARDWARE INTERRUPTS: One source is from an external signal applied to NMI or INTR input pin of
the processor. The interrupts initiated by applying appropriate signals to these input pins are called hardware
interrupts Hardware interrupts are generated by hardware devices when something unusual happens; this
could be a key-press or a mouse move or any other action. It can be divided into two1. Maskable2. Non
maskable
➢ Maskable Interrupts: There are some interrupts which can be masked (disabled)or enabled by the
processor.
➢ Non-Maskable Interrupts: There are some interrupts which cannot be masked out or ignored by
the processor. These are associated with high priority tasks which cannot be ignored (like memory
parity or bus faults).
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
no in the range 0 to 255(00 to FF). Interrupts are divided into three groups
• Type 0 to Type 4 (Dedicated Interrupts)
- TYPE 0 interrupt represents division by zero situation.
- TYPE 1 interrupt represents single-step execution during the debugging of program.
- TYPE 2 interrupt represents non-maskable NMI interrupt.
- TYPE 3 interrupt represents break-point interrupt.
- TYPE 4 interrupt represents overflow interrupt.
• Type 5 to 31(Not used by 8086, reserved for higher processor like
80286,80386….
For every interrupt, there must be an interrupt service routine (ISR), or interrupt handler. When an
TYPES OF INTERRUPTS:
Predefined Interrupts:
Divide-By-Zero Interrupt-Type 0: The 8086 will automatically do a type 0 interrupt if the result of a DIV
operation or an IDIV operation is too large to fit in the destination register. For a type 0 interrupt, the 8086
pushes the flag register on the stack, resets IF and TF and pushes the return addresses on the stack.
Single Step Interrupt-Type 1: The use of single step execution feature is found in some of the monitor &
debugger programs. When we tell a system to single step, it will execute one instruction and stop. We can
then examine the contents of registers and memory locations.
Non-maskable Interrupt-Type 2: The 8086 will automatically do a type 2 interrupt response when it
receives a low to high transition on its NMI pin. When it does a type 2 interrupt, the 8086 will push the flags
on the stack, reset TF and IF, and push the CS value and the IP value for the next instruction on the stack. It
will then get the CS value for the start of the type 2 interrupt service procedure from address 0000AH and
the IP value for the start of the procedure from address 00008H.
Breakpoint Interrupt-Type 3: The type 3 interrupt is produced by execution of the INT3 instruction. The
main use of the type 3 interrupt is to implement a breakpoint function in a system. The breakpoint feature
executes all the instructions up to the inserted breakpoint and then stops execution. The mnemonic for the
instruction is INT3. Whenever we insert a breakpoint, the system executes the instructions up to the
breakpoint and then goes to the breakpoint procedure.
INTERRUPT PROGRAMMING
Features:
• 8 levels of interrupts.
• Can be cascaded in master-slave configuration to handle 64 levels of interrupts.
• Internal priority resolver.
• Individually maskable interrupts.
Pins Description
CS Active low chip for enabling RD/WR operations.
̅̅̅̅̅
𝐖𝐑 Active low write enable input. This enables to accept command words from CPU
̅̅̅̅
𝐑𝐃 Active low read input. Enables to release status onto data bus
D7 – D0 These pins forms bidirectional data bus that carries 8 bit data either to control word or from
status word register. These also carries interrupt vector information
CAS2 – CAS0 A single 8259A gives 8 interrupts, if more interrupts are required, the 8259A is used in cascaded
mode to provide 64 interrupts lines. Also act as select lines for addressing slaves in 8259A
̅̅̅̅/𝐄𝐍
𝐏𝐒 ̅̅̅̅ This pin is a dual-purpose pin. When chip is used in buffered mode, it can be used as buffer
enable to control buffer transceivers. If not used in buffered mode then pin is used as input to
designate whether chip is used as master or slave.
INT This pin goes high whenever a valid interrupt request is asserted. This is used to interrupt CPU
and is connected to interrupt input of CPU
IR0 – IR7 These pins act as input to accept requests to CPU.
̅̅̅̅̅̅̅
𝐈𝐍𝐓𝐀 This pin is an input used to strobe 8259A interrupt vector data onto to the data bus.