Interrupt Procedure -------------------
The IME (interrupt master enable) flag is reset by DI and prohibits all interrupts. It is set by EI and acknowledges the interrupt setting by the IE register.
1. When an interrupt is generated, the IF flag will be set. 2. If the IME flag is set & the corresponding IE flag is set, the following 3 steps are performed. 3. Reset the IME flag and prevent all interrupts. 4. The PC (program counter) is pushed onto the stack. 5. Jump to the starting address of the interrupt.
Resetting of the IF register, which was the cause of the interrupt, is done by hardware.
During the interrupt, pushing of registers to be used should be performed by the interrupt routine.
Once the interrupt service is in progress, all the interrupts will be prohibited. However, if the IME flag and the IE flag are controlled, a number of interrupt services can be made possible by nesting.
Return from an interrupt routine can be performed by either RETI or RET instruction.
The RETI instruction enables interrupts after doing a return operation.
If a RET is used as the final instruction in an interrupt routine, interrupts will remain disabled unless a EI was used in the interrupt routine or is used at a later time.
The interrupt will be acknowledged during opcode fetch period of each instruction.