© 2000 Scenix Semiconductor, Inc. All rights reserved. 159 SX User’s Manual Rev. 3.1 www.scenix.com Chapter 6 Timers and Interrupts 6.4.6 Return-from-Interrupt Instructions There are two return-from-interrupt instructions available: RETI (Return from Interrupt) RETIW (Return from Interrupt and adds W to RTCC) Both of these instructions cause a return from the current interrupt service routine by restoring W,
STATUS,  FSR,  and  the  program  counter.  The  RETI  instruction  is  a  “plain”  return  from  interrupt,
whereas the RETIW also adds W to the RTCC register prior to the return.
The  RETIW  instruction  adds  W  to  RTCC  before  it  restores  W,  STATUS,  FSR,  and  the  program
counter. This allows RTCC to be restored to the value it contained at the time the main program was
interrupted. To use this feature, the interrupt service routine should check the RTCC register at the
beginning of the routine and again at the end of the routine, and then put the adjustment value into W
before executing the RETIW instruction.
6.4.7 Interrupt Example The following code example shows the part of an interrupt service routine that determines the cause of
an interrupt and jumps to a processing routine based on the cause. In this example, the RB0 and RB1
pins  are  configured  to  operate  as  interrupt  inputs  and  the  RTCC  counter  is  enabled  to  generate
interrupts.
org 0 ;interrupt routine starts at address 000h mov M,#$9 ;set up MODE register to read WKPND_B clr W ;clear W to zero mov !RB,W ;exchange contents of W and WKPND_B and W,#$03 ;mask out unused bits from WKPND_B
;W now indicates cause of interrupt:
;00h = RTCC, 01h = RB0, or 02h = RB1
add $02,W ;add W to program counter for indirect jump jmp rtcc_i ;W=00h, jump to RTCC interrupt service routine jmp rb0_i ;W=01h, jump to RB0 interrupt service routine jmp rb1_i ;W=02h, jump to RB1 interrupt service routine rtcc_i        ... ;RTCC interrupt service routine here reti ;return from interrupt rb0_i         ... ;RB0 interrupt service routine here reti ;return from interrupt rb1_i         ... ;RB1 interrupt service routine here reti ;return from interrupt