Download M16C Assembler Manual

Transcript
Programming Style
4
4.3 Setting Interrupts
4.3.5 Saving and Restoring Registers in Interrupt Handler Routine
When an interrupt is accepted, the following resources are automatically saved to the stack. For
details on how they are saved and restored to and from the stack, refer to Section 4.5.2, "Stack
Area."
• PC (program counter)
• FLG (flag register)
Always be sure to use the REIT instruction to return from the interrupt handler routine. After the
interrupt processing is completed, this instruction restores the registers, return address, etc. from
the stack, thus allowing the main program to restart processing where it left off.
In addition to the automatically saved registers, there may be some other register which is used in
the interrupt handler routine and, therefore, whose previous content needs to be retained. If there is
a such a register, save it to the stack in software. For an example of how registers are saved and
restored in the interrupt handler routine, refer to Section 4.3.6, "Sample Program List 3 (Software
Interrupt)".
Methods for Saving and Restoring Registers
If in addition to the automatically saved registers there is any register which is used in the interrupt
handler routine and, therefore, whose previous content needs to be retained, save it to the stack
area in software. There are two methods for saving and restoring this register. The following
shows the processing procedure for each method.
(1) Using push/pop instructions to save and restore registers
(1a) Saving registers individually
PUSH.B
R0L
PUSH.W R1
(1b) Restoring registers individually
POP.B
R0L
POP.W
R1
(2a) Saving registers collectively
PUSHM
R0,R1,R2,R3,A0,A1
(2b) Restoring registers collectively
POPM
R0,R1,R2,R3,A0,A1
(2) Switching over register banks to save and restore registers
This method will be effective when it is necessary to reduce the overhead time of interrupt
processing.
(a) Using register bank 1
FSET
B
(b) Using register bank 0
FCLR
B
145