/opcodes/retn

Control Flow // RETN (RETurn from Non-maskable interrupt)

Description

This instruction is used at the end of a nonmaskable interrupts service routine to restore the contents of the Program Counter (analogous to the RET instruction). The state of IFF2 is copied back to IFF1 so that maskable interrupts are enabled immediately following the RETN if they were enabled before the nonmaskable interrupt.

Example

If the Stack Pointer contains 1000h and the Program Counter contains 1A45h when a Nonmaskable Interrupt (NMI) signal is received, the CPU ignores the next instruction and instead restarts, returning to memory address 0066h. The current Program Counter contains 1A45h, which is pushed onto the external stack address of 0FFFh and 0FFEh, highorder byte first, and 0066h is loaded onto the Program Counter. That address begins an interrupt service routine that ends with a RETN instruction. Upon the execution of a RETN instruction, the contents of the former Program Counter are popped off the external memory stack, low-order first, resulting in the Stack Pointer again containing 1000h. The program flow continues where it left off with an op code fetch to address 1A45h, order-byte first, and 0066h is loaded onto the Program Counter. That address begins an interrupt service routine that ends with a RETN instruction. Upon the execution of a RETN instruction, the contents of the former Program Counter are popped off the external memory stack, low-order first, resulting in stack pointer contents of 1000h. The program flow continues where it left off with an op code fetch to address 1A45h.

Opcodes