home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / INTERUP2.ZIP / INTERRUP.PRI < prev    next >
Encoding:
Text File  |  1987-12-10  |  3.1 KB  |  69 lines

  1.                      iAPX 86 Interrupt Primer
  2.                      ------------------------
  3.  
  4.                           by Ralf Brown
  5.                               12/87
  6.  
  7.  
  8.  
  9. What is an interrupt?
  10.    An interrupt is a hardware signal that tells the CPU to 
  11.    temporarily stop what it is doing and go do something else.  
  12.    Without interrupts, the CPU would have to constantly check for 
  13.    external events; with interrupts, the CPU can work on 
  14.    something else and still respond to an event as soon as it 
  15.    occurs.
  16.  
  17.    CPUs typically have an instruction to disable interrupts for 
  18.    use when a section of code has to run without being disturbed 
  19.    by external events.  Because of this, most CPUs also have a 
  20.    special interrupt called a Non-Maskable Interrupt (NMI), which 
  21.    is responded to even when all other interrupts are disabled.  
  22.    The NMI is used to signal calamities such as memory failure or 
  23.    imminent power loss.
  24.  
  25. Why so many different interrupts?
  26.    The 8086 family of processors has the ability to recognize 256 
  27.    different interrupts.  They also have the ability to let a 
  28.    program invoke any of these interrupts with a special 
  29.    instruction, known as a software interrupt (as opposed to a 
  30.    hardware interrupt which is signalled from outside the 
  31.    processor).  Software interrupts are treated just like 
  32.    hardware interrupts, except that they are never disabled and 
  33.    do not result in an acknowledgement to other chips in the 
  34.    computer.
  35.  
  36.    Since a program can invoke an interrupt by number rather than 
  37.    by its address (as it has to call subroutines), interrupts are 
  38.    a convenient way of providing services without having to 
  39.    recompile a program whenever the address of the code providing 
  40.    the service changes.  This also allows a user program to 
  41.    enhance the services provided by directing the interrupt to 
  42.    itself.
  43.  
  44. How does an interrupt work?
  45.    The 8086 reserves the lowest 1024 bytes of memory for a table 
  46.    containing the addresses for each of the 256 possible 
  47.    interrupts.  When an interrupt occurs (hardware or software), 
  48.    the processor multiplies its number by 4 and looks at the 
  49.    resulting memory location to find the address of the piece of 
  50.    code which handles the interrupt.  It then places the current 
  51.    address in the program and the processor flags on the stack, 
  52.    and jumps to the beginning of the interrupt handler.
  53.  
  54.    When the interrupt handler finishes, it invokes a special 
  55.    instruction to return from the interrupt.  This instruction 
  56.    takes the previously saved flags and program address off of 
  57.    the stack and places them back in the appropriate registers in 
  58.    the CPU.
  59.  
  60.    The interrupt handler has to be careful to preserve any 
  61.    registers that it uses which are not used to communicate 
  62.    results to the program that invoked the interrupt.  If the 
  63.    interrupt can be triggered by a hardware interrupt (only 
  64.    certain ones can on IBM PC's, XT's, and AT's), then the 
  65.    interrupt handler has to preserve ALL registers, since the 
  66.    interrupt could have happened anywhere.
  67.  
  68.  
  69.