0% found this document useful (0 votes)
28 views8 pages

Neccesity of Interrupts

neccesity of interrupts

Uploaded by

ezekiel nyamu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views8 pages

Neccesity of Interrupts

neccesity of interrupts

Uploaded by

ezekiel nyamu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

Questions : 1. What are interrupts ? 2. Explain the term polling with suitable example.

Necessity of Interrupts

When you have one or more I/O devices connected to a microprocessor system,
any one of them may demand service at any time. The microprocessor can
service these devices in one of the two ways. One way is to use the polling
routine. The other way is to use an interrupt. In the following section, we will
see both ways.

In polling, the microprocessor's software simply checks each of the I/O devices
every so often. During this check, the microprocessor tests to see if any device
needs servicing.

A more desirable method would be the one that allows the microprocessor to be
executing its main program and only stop to service I/O devices when it is told
to do so by the device itself. In effect, the method, would provide an external
asynchronous input that would inform the processor that it should complete
whatever instruction that is currently being executed and fetch a new routine
that will service the requesting device. Once this servicing is completed, the
processor would resume exactly where it left off. This method is called interrupt
method.

The necessity of interrupts in a microprocessor-based system arises from the need for
efficient, real-time handling of external or internal events without wasting CPU resources.
Interrupts allow the microprocessor to respond immediately to critical tasks or events and
then resume normal operations, making systems more efficient and responsive.

Here are key reasons why interrupts are essential:

1. Real-Time Response to Critical Events

Interrupts provide an immediate response to time-sensitive events. For example, in a real-


time system such as an embedded device controlling a robot, certain events like sensor input
or user commands must be addressed promptly. Interrupts ensure that these tasks are handled
as soon as they occur, without waiting for the processor to complete its current task.
 Example: A fire alarm system requires immediate action when a fire sensor detects
smoke. The interrupt signal from the sensor ensures the processor halts any ongoing
processes and triggers the alarm.

2. Efficient Use of Processor Time

In the absence of interrupts, the microprocessor would have to rely on polling, where it
continuously checks devices or conditions for activity. This is inefficient because the
processor wastes time checking for events that may not occur frequently. Interrupts eliminate
the need for continuous polling, allowing the processor to perform other useful tasks and only
respond to an event when it occurs.

 Example: In a keyboard system, without interrupts, the processor would have to


continuously check if a key has been pressed. With interrupts, the processor can
execute other tasks and only be interrupted when a keypress actually happens.

3. Asynchronous Event Handling

Interrupts allow the microprocessor to handle asynchronous events, which occur at


unpredictable times. These events could be generated by external devices (like input/output
peripherals) or internal sources (like timers). The processor cannot predict when these events
will occur, so interrupts are necessary to ensure timely handling.

 Example: A network interface card (NIC) may receive data packets at random times.
The interrupt mechanism allows the microprocessor to stop its current operation and
process the received packet as soon as it arrives.

4. Priority Handling of Multiple Tasks

Interrupts can be assigned different priorities, allowing the system to determine which events
are more important. If multiple interrupts occur, the microprocessor can handle the highest-
priority interrupt first, ensuring that critical tasks are addressed before less important ones.

 Example: In a medical monitoring system, an interrupt from a heart rate sensor might
be given higher priority than one from a temperature sensor, ensuring that life-critical
signals are processed immediately.

5. Multitasking and Time-Sharing

Interrupts are essential in systems that require multitasking or time-sharing, such as operating
systems. They allow the processor to switch between multiple tasks efficiently, ensuring that
important tasks are not delayed by less urgent ones.

 Example: In an operating system, a timer interrupt can be used to ensure that the
processor switches between different applications or processes at regular intervals,
allowing time-sharing between tasks.

6. Hardware and Peripheral Communication


Many hardware peripherals, such as keyboards, printers, and disk drives, communicate with
the processor using interrupts. These devices send interrupt signals when they need attention,
and the processor responds immediately without needing to constantly check their status.

 Example: When a printer is ready to receive data from the processor, it sends an
interrupt signal, and the processor responds by sending the data. Once the data
transfer is complete, the processor resumes its previous task.

7. Power Efficiency

Interrupts help reduce power consumption in embedded systems. The processor can enter a
low-power or sleep mode when there is no immediate task to perform. It only "wakes up" and
consumes power when an interrupt signal is received, making the system more energy-
efficient.

 Example: In battery-operated devices like smartphones, the processor can go to sleep


to conserve power and wake up only when an interrupt, such as a touch input or
incoming call, occurs.

Summary of Benefits of Interrupts:

 Immediate response to critical events.


 Efficient use of CPU time by eliminating unnecessary polling.
 Handling of asynchronous events.
 Prioritized task management through interrupt prioritization.
 Support for multitasking and time-sharing in complex systems.
 Smooth communication with hardware devices.
 Power-saving capabilities in embedded systems.

In conclusion, interrupts are a fundamental feature that enables microprocessors to efficiently


manage resources, handle multiple tasks, and respond quickly to important events, making
systems more responsive and reliable.

Review Questions

1. What are interrupts ?

2. Explain the term polling with suitable example.


1. What are Interrupts?

Interrupts are signals that temporarily halt the execution of the current program and divert
the control of the microprocessor to execute a specific task or service routine. After the
interrupt service routine (ISR) is completed, the microprocessor resumes the execution of the
main program. Interrupts are used to handle urgent or important events, such as I/O device
requests, in a timely manner.

Types of Interrupts in 8085 Microprocessor:

There are two main types of interrupts in the 8085 microprocessor:

 Hardware Interrupts: These are triggered by external devices or hardware signals.


o Example: INTR, RST7.5, RST6.5, RST5.5, TRAP

 Software Interrupts: These are initiated by instructions in the program.


o Example: RST0 to RST7 instructions.

Example of Interrupt:

Consider a situation where a printer needs to print data after receiving a signal from the
microprocessor:

 The microprocessor is executing a main program.


 When the printer sends an interrupt signal, the microprocessor stops the current
program and jumps to the ISR to process the printer's request.
 After completing the print operation, the microprocessor returns to the main program
where it left off.

asm

Polling: Definition and Explanation

Polling is a technique used by a microprocessor or microcontroller where it continuously


checks the status of an external device (such as an input/output device) to see if it requires
service or attention. The processor does this by repeatedly reading the status of the device to
determine whether it is ready for some action, such as sending or receiving data.

In polling, the microprocessor periodically asks each device whether it needs any action to be
taken. If a device requires service, the processor responds accordingly; otherwise, it continues
checking the next device or performs other tasks. Polling can be a simple method for
managing devices, but it is generally less efficient than interrupts because it consumes more
processor time checking devices that may not need attention.
How Polling Works

 The microprocessor runs a continuous loop, where it checks the status of one or more
devices in a predefined order.
 If the device status indicates that it needs attention (e.g., data is ready to be read or
written), the processor performs the necessary actions.
 If no device needs attention, the processor either continues polling or performs other
operations.

Example of Polling

Let’s consider a simple example of polling with a keyboard input.

Problem:

You want to continuously check whether a key has been pressed on a keyboard connected to
the microprocessor. The program checks the keyboard's status and only performs a specific
task if a key is pressed.

Polling Example Code:

POLL_KEYBOARD:
CALL CHECK_KEY_STATUS ; Check if any key is pressed
JZ POLL_KEYBOARD ; If no key is pressed (zero flag set), keep polling
CALL READ_KEY ; If a key is pressed, read the key
JMP PROCESS_KEY ; Jump to process the key input

CHECK_KEY_STATUS:
; Code to check keyboard status
; If a key is pressed, return with zero flag clear (Z=0)
; Otherwise, set zero flag (Z=1)
RET

READ_KEY:
; Code to read the pressed key from the keyboard
RET

PROCESS_KEY:
; Process the key input (perform action based on the key pressed)
JMP POLL_KEYBOARD ; Return to polling after processing the key

Explanation:

 The program enters a polling loop called POLL_KEYBOARD.


 It calls the subroutine CHECK_KEY_STATUS to check the status of the keyboard.
 If no key is pressed (zero flag is set), it keeps polling by jumping back to
POLL_KEYBOARD.

 If a key is pressed (zero flag is cleared), the processor reads the key using the
READ_KEY subroutine and then processes the input.

 After processing the input, the microprocessor returns to polling.

Example of Polling in a Real-World Scenario

Printer Example:

Imagine a microprocessor managing a printer. The processor needs to check whether the
printer is ready to receive more data. It does this by polling the printer to check if it's free.

POLL_PRINTER:
CALL CHECK_PRINTER_STATUS ; Check if the printer is ready
JZ POLL_PRINTER ; If the printer is not ready, keep polling
CALL SEND_DATA_TO_PRINTER ; If the printer is ready, send data
JMP POLL_PRINTER ; Continue polling after sending data

CHECK_PRINTER_STATUS:
; Check printer status
; If printer is ready, clear the zero flag (Z=0)
; If printer is busy, set the zero flag (Z=1)
RET

SEND_DATA_TO_PRINTER:
; Send the required data to the printer
RET

Explanation:
 The processor continuously checks the status of the printer using the
CHECK_PRINTER_STATUS subroutine.
 If the printer is busy, the processor stays in the polling loop.
 If the printer is ready, the processor sends data and resumes polling.

Polling vs. Interrupts

 Polling involves the processor constantly checking the device status, which can waste
CPU time, especially if no devices need attention for a long period.
 Interrupts are a more efficient alternative, where the device sends a signal (interrupt)
to the processor when it requires attention. The processor can handle other tasks and
only respond to the device when it’s necessary.

Key Differences:

Feature Polling Interrupts


CPU Wastes CPU time by repeatedly checking Efficient, CPU is free for other
Utilization devices tasks until interrupted
Inefficient for systems with infrequent Efficient, especially for real-time
Efficiency
events systems
More complex due to the need for
Complexity Simple to implement
interrupt handling
Response Delayed, as the processor may not check
Fast response to critical events
Time the device immediately

Advantages of Polling

1. Simple Implementation: Polling is straightforward to implement in many basic


systems where complexity is not a concern.
2. Predictability: The sequence in which devices are polled can be predetermined,
making it easier to manage simpler systems.
3. No Special Hardware Required: Unlike interrupts, polling doesn’t need dedicated
interrupt hardware or complicated service routines.

Disadvantages of Polling

1. Wastes Processor Time: The CPU spends valuable time checking devices even when
they don’t need service, reducing system efficiency.
2. Slower Response Time: Since polling occurs at intervals, a device might have to wait
before being checked, leading to slower response times.
3. Scalability Issues: Polling becomes inefficient as the number of devices increases
because the processor has to check each device individually.

Summary:

 Polling is a technique where the processor regularly checks each device to see if it
needs attention, but it is less efficient than using interrupts.
 Polling can lead to wasted processor time because the microprocessor might spend
time checking devices that don't need service.
 In contrast, interrupts allow the processor to perform other tasks and only respond
when necessary.
 Polling is simple to implement but can lead to inefficiency in larger systems or
systems with time-sensitive tasks.

You might also like