Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Systems / Difference Between Interrupt and Trap

Difference Between Interrupt and Trap

June 27, 2011 Posted by Indika

Interrupt vs Trap

In any computer, during its normal execution of a program, there could be events that can cause the CPU to temporarily halt. Events like these are called interrupts. Interrupts can be caused by either software or hardware faults. Hardware interrupts are called (simply) Interrupts, while software interrupts are called Exceptions or Traps. An Exception is an automatically generated software interrupt, while a Trap is a software-invoked interrupt initiated by the programmer. Once an interrupt (software or hardware) is raised, the control is transferred to a special subroutine called ISR (Interrupt Service Routine) that can handle the conditions that are raised by the interrupt.

What is an Interrupt?

The term Interrupt is usually reserved for hardware interrupts. They are program control interruptions caused by external hardware events. Here, external means external to the CPU. Hardware interrupts usually come from many different sources such as timer chip, peripheral devices (keyboards, mouse, etc.), I/O ports (serial, parallel, etc.), disk drives, CMOS clock, expansion cards (sound card, video card, etc). That means hardware interrupts almost never occur due to some event related to the executing program. For example, an event like a key press on the keyboard by the user, or an internal hardware timer timing out can raise this kind of interrupt and can inform the CPU that a certain device needs some attention. In a situation like that the CPU will stop whatever it was doing (i.e. pauses the current program), provides the service required by the device and will get back to the normal program. When hardware interrupts occur and the CPU starts the ISR, other hardware interrupts are disabled (e.g. in 80×86 machines). If you need other hardware interrupts to occur while the ISR is running, you need to do that explicitly by clearing the interrupt flag (with sti instruction). In 80×86 machines, clearing the interrupt flag will only affect hardware interrupts.

What is a Trap?

A Trap can be identified as a transfer of control, which is initiated by the programmer. The term Trap is used interchangeably with the term Exception (which is an automatically occurring software interrupt). But some may argue that a trap is simply a special subroutine call. So they fall in to the category of software-invoked interrupts. For example, in 80×86 machines, a programmer can use the int instruction to initiate a trap. Because a trap is always unconditional the control will always be transferred to the subroutine associated with the trap. The exact instruction, which invokes the routine for handling the trap is easily identified because an explicit instruction is used to specify a trap.

What is the difference between Interrupt and Trap?

Interrupts are hardware interrupts, while traps are software-invoked interrupts. Occurrences of hardware interrupts usually disable other hardware interrupts, but this is not true for traps. If you need to disallow hardware interrupts until a trap is served, you need to explicitly clear the interrupt flag. And usually the interrupt flag on the computer affects (hardware) interrupts as opposed to traps. This means that clearing this flag will not prevent traps. Unlike traps, interrupts should preserve the previous state of the CPU.

Related posts:

Difference Between System Call and Interrupt Difference Between Interrupt and Exception Difference Between Exception and Error Difference Between System Call and Function Call Difference Between Intel Core i3 and 2nd Generation Intel Core i3 Processors

Filed Under: Systems Tagged With: automatic software interrupt, exception, exceptions, Hardware interrupt, interrupt, interrupt flag, interrupts, ISR, program execution, software interrupt, software-invoked interrupt, subroutine call, trap, Traps

About the Author: Indika

Indika, BSc.Eng, MSECE Computer Engineering, PhD. Computer Science, is an Assistant Professor and has research interests in the areas of Bioinformatics, Computational Biology, and Biomedical Natural Language Processing.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Terrorism and Crime

Difference Between Microsoft Surface Pro and Lenovo IdeaPad Yoga 11S

Difference Between Platinum and White Gold

Difference Between Platinum and White Gold

Difference Between Archival and Backup

Difference Between Allele and Genotype

Difference Between Allele and Genotype

Latest Posts

  • What is the Difference Between Elementary and Complex Reaction
  • What is the Difference Between Ataxia and Apraxia
  • What is the Difference Between Chlorine Fluorine and Astatine
  • What is the Difference Between B Cell and T Cell Leukemia
  • What is the Difference Between Animal Pole and Vegetal Pole
  • What is the Difference Between Terminal and Bridging Carbonyls
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018 Difference Between. All rights reserved. Terms of Use and Privacy Policy: Legal.