Chapter 4: Interrupts/Exceptions Flashcards
Why do we need interupts?
A microprocessor is likely to be required to respond to events that might occur; for example a button press, a stroke on a keyboard, or a reading from a sensor, and it will have dedicated input wires to allow this.
The two fundamental paradigms as to how a processor can be programmed to respond to events?
whether the programme finds out for itself whether an event has occurred, or whether the event tells the processor that an event has occurred. In the first case the programme is in charge, whereas in the second the event is in charge.
What is a programme-controlled input/output?
would consist of a loop that checks or polls the input port. The speed at which the programme can respond to an event depends on the number of cycles in that loop (if the event occurs just after one check, the programme must go round the loop again before it realises that an event has occurred).
Disadvantages of programme-controlled input/output?
The problem with this method is that the processor cannot do anything else whilst waiting for the event to occur.
The alternative to programme-controlled input/output?
The alternative is for the event to interrupt the processor when an event occurs. The processor then switches to a set of code called an interrupt handler or interrupt service routine which deals with the event before returning to the point in the main programme for it to continue
How can an external event cause an event to be executed?
When an external event occurs, it asserts an interrupt request line. This might occur at any time during the main programme. The event causes the programme counter to change to the address stored in an interrupt vector corresponding to the start of the interrupt handler (a vector stores an address) and also saves a return address.
Once the current instruction has completed, the programme then switches to the interrupt handler. This needs to be written carefully so that the current status of the registers is saved to the stack before responding to the external event.
After this response, the saved registers must be restored before returning to the main programme using the stored return address. Instruction sets often provide a special return from interrupt instruction.
ISR diagram?
How are exceptions similar to interrupts?
An exception operates in a similar manner to an interrupt in that 1) it can occur at any time within the main programme, and 2) it initiates the execution of a special set of code called the exception handler.
Differences between interrupt and exceptions?
However, in contrast to an interrupt, an exception occurs when the microprocessor encounters an error condition.
Common causes of error?
Division by zero
Memory access failure
wrong address
write to read only
…and can be caused by bugs in the software.