Hardware Reference
In-Depth Information
5. When finishing the phone conversation, you hang up the phone, open the topic to the
page where you placed the bookmark, and resume reading. Similarly, after taking
some actions appropriate to the interrupt, the microprocessor will jump back to the
next instruction, after the interrupt occurred, and resume program execution. This
can be achieved easily because the address of the instruction to be resumed was
saved in memory (the stack). Most microprocessors do this by executing a return-
from-interrupt instruction.
6.2.2 Why Are Interrupts Used?
Interrupts are useful in many applications, such as the following:
Coordinating I/O activities and preventing the CPU from being tied up during
the data transfer process . The CPU needs to know if the I/O device is ready before
it can proceed. Without the interrupt capability, the CPU will need to check the
status of the I/O device continuously or periodically. The interrupt mechanism is
often used by the I/O device to inform the CPU that it is ready for data transfer.
CPU time can thus be utilized more efficiently because of the interrupt mechanism.
Interrupt-driven I/O operations will be explained in more detail in later chapters.
Performing time-critical applications . Many emergent events, such as power
failure and process control, require the CPU to take action immediately. The
interrupt mechanism provides a way to force the CPU to divert from normal
program execution and take immediate actions.
Providing a graceful way to exit from an application when a software error occurs .
The service routine for a software interrupt may also output useful information
about the error so that it can be corrected.
Reminding the CPU to perform routine tasks . There are many microprocessor
applications that require the CPU to perform routine work, such as the following:
1. Keeping track of time of day . Without the timer interrupt, the CPU will need
to use program loops in order to update the current time. The CPU cannot do
anything else without a timer interrupt in this application. The periodic timer
interrupts prevent the CPU from being tied up.
2. Periodic data acquisition . Some applications are designed to acquire data
periodically.
3. Task switching in a multitasking operating system . In a modern computer
system, multiple application programs are resident in the main memory, and the
CPU time is divided into many short slots (one slot may be from 10 to 20 ms).
A multitasking operating system assigns a program to be executed for one time
slot. At the end of a time slot or when a program is waiting for the completion
of an I/O operation, the operating system takes over and assigns another
program for execution. This technique is called multitasking . Multitasking can
dramatically improve the CPU utilization and is implemented by using periodic
timer interrupts.
6.2.3 Interrupt Maskability
Depending on the situation and application, some interrupts may not be desired or needed
and should be prevented from affecting the CPU. Most microprocessors and microcontrollers
have the option of ignoring these interrupts. These types of interrupts are called maskable inter-
rupts . There are other types of interrupts that the CPU cannot ignore and must take immediate
actions for; these are nonmaskable interrupts . A program can request the CPU to service or
 
Search WWH ::




Custom Search