/opcodes/reti

Control Flow // RETI (RETurn from Interrupt)

Description

This instruction is used at the end of a maskable interrupt service routine to: • Restore the contents of the Program Counter (analogous to the RET instruction) • Signal an I/O device that the interrupt routine is completed. The RETI instruction also facilitates the nesting of interrupts, allowing higher priority devices to temporarily suspend service of lower priority service routines. However, this instruction does not enable interrupts that were disabled when the interrupt routine was entered. Before doing the RETI instruction, the enable interrupt instruction (EI) should be executed to allow recognition of interrupts after completion of the current service routine.

Example

Assume that there are two interrupting devices, A and B, connected in a daisy-chain configuration, with A having a higher priority than B. A B + IEO IEI IEI IEO INT B generates an interrupt and is acknowledged. The interrupt enable out, IEO, of B goes Low, blocking any lower priority devices from interrupting while B is being serviced. Then A generates an interrupt, suspending service of B. The IEO of A goes Low, indicating that a higher priority device is being serviced. The A routine is completed and a RETI is issued resetting the IEO of A, allowing the B routine to continue. A second RETI is issued on completion of the B routine and the IE0 of B is reset (High), allowing lower-priority devices interrupt access.

Opcodes