Exceptions and interrupts are unexpected events that disrupt the normal flow of instruction execution, when it occurs following things happens
- move the current PC into another register, call the EPC
- record the reason for the exception in the Cause register
- automatically disable further interrupts or execptions from occuring, by left-shifting the Status register
- change control (jump) to a hardwired exception handler address
To return from a handler, your processor may perform the following actions:
- move the contents of the EPC register to the PC.
- re-enable interrupts and exceptions, by right-shifting the Status register
Still have some differences, lets see that
1. Interrupt9 (devices like the hard disk, graphics card, I/O ports, etc). is an as asynchronous event that is normally generated by hardware( devices like the hard disk, graphics card, I/O ports, etc) not in sync with processor instruction execution where Exceptions are synchronous events generated when processor detects any predefined condition(overflow, underflow, nan) while executing instructions.
2. Interrupts are handled by the processor after finishing the current instruction, exceptions on the other hand are divided into three kinds.
- Faults
- Faults are detected and serviced by the processor before the faulting instructions.
- Traps ( It’s caused by division by zero or invalid memory access. It’s also the usual way to invoke a kernel routine (a system call) because those run with a higher priority than user code. Handling is synchronous (so the user code is suspended and continues afterwards). In a sense they are “active” – most of the time, the code expects the trap to happen and relies on this fact)
- Traps are serviced after the instruction causing the trap. User defined interrupts go into this category and can be said to be traps.
- Aborts
- Aborts are used only to signal severe system problems, when operation is no longer possible