What are the difference between the trap and interrupt? What is the use of each function?



An interrupt is generally initiated by an I/O device, and causes the CPU to stop what its doing, save its context, jump to the appropriate interrupt service routine, complete it, restore the context, and continue execution. For example, a serial device may assert the interrupt line and then place an interrupt vector number on the data bus. The CPU uses this to get the serial device interrupt service routine, which it then executes as above. 


A trap is usually initiated by the CPU hardware. Whenever the trap condition occurs (on arithmetic overflow, for example), the CPU stops what it's doing, saves the context, jumps to the appropriate trap routine, completes it, restores the context, and continues execution. For example, if overflow traps are enabled, adding two very large integers would cause the overflow bit to be set AND the overflow trap service routine to be initiated.

0 comments:

Feel free to contact the admin for any suggestions and help.