Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Interrupts: For Example Let Us Take A Task That Involves Two Activities

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

INTERRUPTS

An interrupt is a signal to the processor emitted by hardware or software indicating an event


that needs immediate attention.

Our processor repeatedly keeps on checking for the SIN and SOUT bits for the synchronization
in the program. Hence, the processor does not do any things useful other than running the
infinite loop. To avoid this situation input/output devices can have the concept of interrupts .
When the input/output device is ready it could signal the processor on a separate line called
interrupt request line. On receiving the interrupt the processor reads the input output device
and hence removing the infinite loop waiting mechanism.

For example let us take a task that involves two activities :


1. Perform some computation
2. Print the result

Repeat the above two steps several times in the program, let the program contain 2 routines
COMPUTE and PRINT routine.

Method #1 :
The COMPUTE routine passes N lines to the PRINT routine and the PRINT routine then prints
the N lines one by one on a printer. All this time the COMPUTE routine keeps on waiting and
does not do anything useful.

Method #2 :
The COMPUTE routine passes N lines to the PRINT routine. The PRINT routine then sends
one line to the printer and instead of printing that line it execute itself and passes the control to
the COMPUTE routine . The COMPUTE routine continuous it activity, once the line has been
printed the printers sends an interrupt to the processor of the computer. At this point the
COMPUTE routine is suspended and the PRINT routine is activated and the PRINT routine
send second line to the printer so that the printer can keep on printing the lines and the process
continues.

TYPES OF INTERRUPTS
Although interrupts have highest priority than other signals, there are many type of interrupts
but basic type of interrupts are ->

1. Hardware Interrupts: If the signal for the processor is from external device or
hardware is called hardware interrupts.
Example: from keyboard we will press the key to do some action this pressing of key in
keyboard will generate a signal which is given to the processor to do action, such interrupts are
called hardware interrupts.

Hardware interrupts can be classified into two types ->

• Maskable Interrupt: The hardware interrupts which can be delayed when a much
highest priority interrupt has occurred to the processor.
• Non Maskable Interrupt: The hardware which cannot be delayed and should process
by the processor immediately.

2. Software Interrupts: Software interrupt can also divided in to two types they are ->

• Normal Interrupts: the interrupts which are caused by the software instructions are
called software instructions.
• Exception: unplanned interrupts while executing a program is called Exception. For
example: while executing a program if we got a value which should be divided by zero
is called a exception.

NEED FOR INTERRUPTS


• The operating system is a reactive program

1. When you give some input it will perform computations and produces output but
meanwhile you can interact with the system by interrupting the running process or you
can stop and start another process

• This reactiveness is due to the interrupts


• Modern operating systems are interrupt driven

INTERRUPT SERVICE ROUTINE AND


IT’S WORKING
The routine that gets executed when an interrupt request is made is called as interrupt service
routine.
• PC=i
• PC= address of Interrupt handler roiutine
• PC=i+1
• Step 1: When the interrupt occurs the processor is currently executing i’th instruction
and the program counter will be currently pointing to (i + 1)th instruction.
• Step 2: When the interrupt occurs the program counter value is stored on the processes
stack.
• Step 3: The program counter is now loaded with the address of interrupt service routine.
• Step 4: Once the interrupt service routine is completed the address on the processes
stack is pop and place back in the program counter.
• Step 5: Execution resumes from (i + 1)th line of COMPUTE routine.

INTERRUPT HARDWARE
Many computers have facility to connect two or more input and output devices to it like laptop
may have 3 USB slots. All these input and output devices are connected via switches as shown
-

So there is a common interrupt line for all N input/output devices and the interrupt handling
works in the following manner ->

1. When no interrupt is issued by the input/output devices then all the switches are open
and the entire voltage from Vdd is flown through the single line INTR and reaches the
processor. Which means the processor gets a voltage of 1V.
2. When the interrupt is issued by the input/output devices then the switch associated with
the input/output device is closed, so the entire current now passes via the switches
which means the hardware line reaching the processes i.e INTR line gets 0 voltage.
This is an indication for the processor that an interrupt has occurred and the processor
needs to identify which input/output device has triggered the interrupt
3. The value of INTR is a logical OR of the requests from individual devices.
4. The resistor R is called as a pull up resistor because it pulls the line voltage to high
voltage state when all switches are open( no interrupt state).

ENABLING AND DISABLING


INTERRUPTS
An interrupt can stop the currently executed program temporarily and branch to an interrupt
service routine.

An interrupt can occur at any time during the execution of a program.

Because of the above reasons it may be some time necessary to disable the interrupt and enable
it later on in the program. For this reason some processor may provide special machine
instructions such as interrupt enable an interrupt disable that performs these tasks.

Let us take an example of recursive interrupt problem ->

Let’s assume that an interrupt has occurred and the interrupt service routine is about to be
executed. The interrupt line is still high and it may go low only when the interrupt routine is
returned. This may take some time during which the processor may think that some more
interrupts have arrived and needs to be scheduled first so that the interrupt service routine do
not leads to an infinite loop of interrupts.

There are two methods to handle the situation:

• Method 1 : As soon as the interrupt service routine is entered all interrupts are disabled.
The interrupts are enabled only while exiting the interrupt service routine. Also note
that the program written for the interrupt service routine has to enable and disable the
interrupts in this case. This is done explicitly by the programmer.
• Method 2 : In case of simple processor, the processor can disable the interrupts when
the interrupt service routine is entered. It will enable the interrupt when the interrupt
service routine is about to exit. This method is different from first method as in first
method we had to explicitly write the program for the interrupt service routines to
enable and disable the interrupts, where is in this case the processor has inbuilt
mechanism to perform this task.

HANDLING MULTIPLE DEVICES


There could be scenarios when there are multiple input/output devices connected to the CPU
that could be raising interrupts, since these interrupts are raised at a random time there can be
several issues like->
• How will the processor identify the device using the interrupt
• How will the processor handle two simultaneous interrupts
• Should the device be allowed to raise an interrupt while another interrupt service routine
is already being executed

How to identify the device raising the interrupts?

The status register can be used to identify the device using an interrupt. When a device raises
an interrupt it will set a specific bit to one . That bit is called IRQ(Interrupt ReQuest) .

IRQs are hardware lines over which devices can send interrupt signal to the microprocessor

When you add a new device to a PC you sometime need to set its IRQ number by setting a
DIP switch. Earlier the KIRQ bit is set to 1 when an interrupt is taken from the keyboard and
the DIRQ bit it was set to 1 while displaying an output.

DISADVANTAGES -> A lot of time spent in checking for the IRQ bits of all the devices,
considering that most of devices are generating interrupts at a random time.

You might also like