[opensource] minutes

Jim Dinan dinan at cse.ohio-state.edu
Fri Jan 20 10:22:50 EST 2006

a.lathrop wrote:
>         - What's the difference between and interrupt and a trap?

We weren't able to reach a consensus on this last night so I promised 
I'd do some homework and post the final word on-list.

I found a good explanation in the online text "The Art of Assembly 
Language" by Randy Hyde (http://webster.cs.ucr.edu/AoA/).  For anyone 
who is interested in learning x86 assembler, this is a great place to 
start.  Here's what Randy says:

(excerpted from:

The concept of an interrupt is something that has expanded in scope over 
the years. The 80x86 family has only added to the confusion surrounding 
interrupts by introducing the int (software interrupt) instruction. 
Indeed, different manufacturers have used terms like exceptions, faults, 
aborts, traps, and interrupts.. Unfortunately, there is no clear 
consensus as to the exact meaning of these terms. ...

On the 80x86, there are three types of events commonly known as 
interrupts: traps, exceptions, and interrupts (hardware interrupts)...

Although the terms trap and exception are often used synonymously, we 
will use the term trap to denote a programmer initiated and expected 
transfer of control to a special handler routine. In many respects, a 
trap is nothing more than a specialized subroutine call. Many texts 
refer to traps as software interrupts. The 80x86 int instruction is the 
main vehicle for executing a trap.

An exception is an automatically generated trap (coerced rather than 
requested) that occurs in response to some exceptional condition. 
Generally, there isn't a specific instruction associated with an 
exception[1], instead, an exception occurs in response to some 
degenerate behavior of normal 80x86 program execution. Examples of 
conditions that may raise (cause) an exception include executing a 
division instruction with a zero divisor, executing an illegal opcode, 
and a memory protection fault.

Hardware interrupts, the third category that we will refer to simply as 
interrupts, are program control interruption based on an external 
hardware event (external to the CPU).

Another difference that he doesn't mention here is that in general 
interrupts are maskable and traps are not.  Any CPU with interrupts will 
have flags that can be set to disable some or all interrupts.  A trap, 
on the other hand, is specifically requested by the programmer (eg to 
jump to some system code - in a pinnacle of logical reasoning, traps are 
accomplished with the 'int' instruction on the x86) so it does not make 
sense to mask traps.

- jim.

James Dinan <dinan at cse.ohio-state.edu>

More information about the Opensource mailing list