We're looking for your comments on how to best organize the wiki's content.
RFI
RFI (Return From Interrupt) is one of the Special opcodes in the DCPU-16 specification. It cleans up after and returns from an interrupt.
Contents |
[edit] Usage
RFI arg1
RFI retrieves register A from the stack, turns off interrupt queueing, and retrieves PC from the stack.
arg1 is ignored and has no effect on what RFI does at all.
[edit] Justification
Although it is technically possible to return from an interrupt manually with other opcodes, this is not stable and is therefore discouraged.
The instability stems from the fact that to return from an interrupt back to the main program, several things must happen:
- The
Aregister should be retrieved from the stack. - Interrupt queueing should be turned off.
- Finally,
PCmust be popped from the stack.
Once interrupt queueing is turned off, another interrupt could come and delay return to the main program. Although PC is still retained in the stack from the first interrupt, a long series of interrupts can prevent returning to the main program indefinitely.
Although the above problem is not completely stopped by RFI, the main program at least is able to execute one instruction between interrupts. Eventually (if such a situation was prepared for), this will give the operator an opportunity to disable interrupts again without requiring a forced shutdown.
[edit] Example
SET IA, myISR ; interrupts will be handled by myISR (Interrupt Service Routine), below SET a, 1 INT a ADD a, 2 :end SET pc, end :myISR SET b, 1 ADD b, a RFI a ; continues execution at ADD a, 2
[edit] Processing
In binary machine code, this Special opcode's five-bit representation is: 0b0 1011 (0x0b)
The instruction takes three cycles to execute, plus any additional cycles necessary to evaluate the argument.
[edit] References
- DCPU-16 specification v1.7 (Copyright 2012 Mojang)
| ||||||||

