Article

Functions Trap and Interrupt

Topic: LearningPublished January 9, 2012
No ratings yet3,965 viewsSign in to rate

Trap and Interrupt are signals generated by software and hardware respectively. They break down the normal execution of the program. A brief description of trap and interrupt is given below.

Trap:

A trap is a software-generated interrupt (signal) caused by an error. Trap is also referred to as software interrupt. Software triggers an interrupt by executing special operation called system call.

Usually, trap is triggered when a numeric value is divided by zero, or unknow
I/O device is accessed, etc. A trap will occur at exactly the same point of the program, whenever a program runs.

Interrupt:

An interrupt is a hardware-generated signal. It is sent to the CPU by an external hardware device such as I/O device. The CPU has a wire called the interrupt request line. An external hardware device sends interrupt signals (or requests) to the CPU through this line.

Hardware may trigger an interrupt at any time by sending a signal to the CPU. So an interrupt is dependent on the relative timing between the interrupting device and the CPU. Suppose an I/O module is performing I/O operation. It sends an interrupt signal to the CPU when the I/O operation is completed.

When the CPU is interrupted, then it: Suspends its current activities (such as execution of program). It performs a state save (i.e. saves the current state of the program counter (PC). Similarly, other state information is also saved). In many computer systems, this information is stored in a special Program Status Word (PSW) register. It transfers the control to the interrupt service routine. The interrupt service routine is executed; on completion, the CPU resumes the interrupted program.

Thus the application program does not have to contain any special code to accommodate the interrupts. The CPU and the operating system are responsible for suspending the program and then resuming it after performing necessary interrupt processing.

Interrupts are the important part of computer architecture and operating system. Each machine has its own interrupt mechanism, but most of the functions are common. When an interrupt is occurred, the control must be transferred to the appropriate interrupt service routine. Similarly, interrupt must be handled quickly.

In a computer system, only a predefined interrupts can be occurred, so an array of pointer is used to store the addresses of interrupt routines. This array of pointer is called the interrupt vector. Each trap and interrupt is associated with an index into that vector. The index values are the unique device numbers that provide the address of the interrupt service routine for interrupting device. The interrupt service routine is generally accessed through an interrupt vector.

The earlier computer systems stored the interrupt address in a fixed location or in a location indexed by the device number. However, modern computers use the stack for this purpose.

Classes of Interrupts:

There are many classes of interrupts, but the most common classes of interrupts are:

1. Program Check Interrupts:
Program Check Interrupts are caused by different problems during program execution. These problems may include division by zero, arithmetic overflow or underflow, incorrect format of input data etc. Many systems allow users, to specify their own routines to be executed when a Program Check Interrupt occurs.

2. Supervisor Call Interrupts:

Supervisor Call Interrupt is initiated by a running process that executes the supervisor call instruction. This type of interrupt is a user's request for a particular system service such as for performing I/O operation etc.

3. Timer Interrupts:

Timer interrupt is generated by timer within the CPU. Timer interrupt allows the operating system to perform certain functions on regular intervals of time.

4. I/O Interrupts:

I/O interrupts are generated by I/O controller (or I/O hardware). The I/O controller sends signal to the CPU that the status of device has changed I/O interrupts are caused when an I/O operation completes, an I/O error occurs, an I/O device gets ready etc.

5. External Interrupts:

These interrupts are caused by pressing the interrupt key by the operator, or receipt of a signal from another processor on a multiprocessor system.

6. Machine Check Interrupts:

These interrupts are caused by failure of any hardware component.

Article author

About the Author

Imran Zafar writes articles about computer basics and database management such as Structured Query Language., types of database language and basics of computer.

Further reading

Further Reading

4 total

Article

Design has been at the centre of our perception of information, brands and entertainment in the world that is now digital first. Whether you browse social media, watch YouTube videos, or pass a billboard, you probably have encountered both visual communication design and graphic design, yet most likely, you were not aware of the distinction between the two. Although these two fields are closely related and in many instances overlap, they have different purposes and require di

July 21, 2025

Article

Dr. Ann Marie Egloff understands that engaging in philanthropy isn’t about just donating funds; it’s about the values and intention behind that action. Whether you’re donating money, volunteering time, or sharing your skills, giving back can take many forms and fit into any lifestyle. According to Dr. Ann Marie Egloff, the most rewarding experiences often come from aligning your efforts with causes that resonate personally. By clarifying your motivations, setting though

May 27, 2025

Article

Learning to play the guitar is an exciting and rewarding experience. Whether you’re a complete beginner or have been playing for years, guitar lessons can help you unlock your full musical potential and take your skills to the next level. But what exactly do guitar lessons offer, and how can they benefit you? Let’s dive in! 1. A Structured Learning Path One of the biggest advantages of taking guitar lessons is the structure they provide. While it’s easy to get lost in the s

February 1, 2025

Article

SVPT Saraswati School is widely regarded as one of the Best CBSE Schools in Thane, offering a holistic and well-rounded education that goes beyond academics. Situated in a peaceful and conducive learning environment, this institution provides a blend of modern infrastructure, dedicated faculty, and extracurricular activities, ensuring that students develop both academically and personally. A Legacy of Excellence in Education:rnSVP Saraswati School has built a reputation over

November 26, 2024