Interrupt Subroutines
7-14
Example 7–8. Hand-Coded Assembly ISR Allowing Nesting of Interrupts
* Assume Register B0–B5 & A0 are the only registers used by the
* ISR and no other functions are called
STW
B0,*B15––
; store B0 to stack
||
MVC
IRP, B0
; save IRP
STW
A0,*B15––
; store A0 to stack
||
MVC
IER, B1
; save IER
||
MVK
mask,A0
; setup a new IER (if desirable)
STW
B1,*B15––
; store B1 to stack
||
MVC
A0, IER
; setup a new IER (if desirable)
STW
B2,*B15––
; store B2 to stack
||
MVC
CSR,A0
; read current CSR
STW
B3,*B15––
; store B3 to stack
|| OR
1,A0,A0
; set GIE bit field in CSR
STW
B4,*B15––
; store B4 to stack
STW
B5,*B15––
; store B5 to stack
||
MVC
A0,CSR
; write new CSR with GIE enabled
STW
B0,*B15––
; store B0 to stack (contains IRP)
STW
B1,*B15––
; store B1 to stack (contains IER)
STW
A0,*B15––
; store A0 to stack (original CSR)
* Beginning of ISR code
...
* End of ISR code
B
restore
; Branch to restore routine
; disable CSR in delay slots of branch
MVKL
0FFFEh,A0
; create mask to disable GIE bit
MVKLH
0FFFFh,A0
MVC
CSR,B5
; read current CSR
AND
A0,B5,B5
; AND B5 with mask
MVC
B5,CSR
; write new CSR with GIE disabled
restore
; restore routine begins at next line
LDW
*++B15,A0
; restore A0 (original CSR)
LDW
*++B15,B1
; restore B1 (contains IER)
LDW
*++B15,B0
; restore B0 (contains IRP)
LDW
*++B15,B4
; restore B4
LDW
*++B15,B3
; restore B3
LDW
*++B15,B5
; restore B5
LDW
*++B15,B2
; restore B2
||
MVC
B0,IRP
; restore original IRP
B
IRP
; return from interrupt
LDW
*++B15,B1
; restore B1
MVC
B1,IER
; restore original IER
LDW
*++B15,A0
; restore A0
LDW
*++B15,B0
; restore B0
MVC
A0,CSR
; restore original CSR
; to complete before branch is taken