
CPU16
REFERENCE MANUAL
INSTRUCTION PROCESS
MOTOROLA
7-7
Subroutines can be called by short (BSR) or long (LBSR) branches, or by a jump
(JSR). The RTS instruction returns control to the calling routine. BSR consists of an 8-
bit opcode with an 8-bit operand. LBSR consists of an 8-bit prebyte and an 8-bit op-
code in one word, followed by an operand word. JSR consists of an 8-bit opcode with
a 20-bit argument. RTS consists of an 8-bit prebyte and an 8-bit opcode in one word.
When a subroutine instruction is executed, PK : PC contain the address of the calling
instruction plus $0006. All three calling instructions stack return PK : PC values prior
to processing instructions from the new instruction stream. In order for RTS to work
with all three calling instructions, however, the value stacked by BSR must be adjust-
ed.
LBSR and JSR are two-word instructions. In order for program execution to resume
with the instruction immediately following them, RTS must subtract $0002 from the
stacked PK : PC value. BSR is a one-word instruction — it subtracts $0002 from PK :
PC prior to stacking so that execution will resume correctly after RTS.
7.3.2.4 Interrupts
An interrupt routine usually performs a critical task, then returns control to the inter-
rupted instruction stream. Interrupts are a type of exception, and are thus subject to
special rules regarding execution process.
SECTION 9 EXCEPTION PROCESSING
covers
interrupt exception processing in detail. This discussion is limited to the effects
of SWI (software interrupt) and RTI (return from interrupt) instructions.
Both SWI and RTI consist of an 8-bit prebyte and an 8-bit opcode in one word. SWI
initiates synchronous exception processing. RTI causes execution to resume with the
instruction following the last instruction that completed execution prior to interrupt.
Asynchronous interrupts are serviced at instruction boundaries. PK : PC
+
$0006 for
the following instruction is stacked, and exception processing begins. In order to re-
sume execution with the correct instruction, RTI subtracts $0006 from the stacked val-
ue.
Interrupt exception processing is included in the SWI instruction definition. The PK :
PC value at the time of execution is the first word address of SWI plus $0006. If this
value were stacked, RTI would cause SWI to execute again. In order to resume exe-
cution with the instruction following SWI, $0002 is added to the PK : PC value prior to
stacking.
F
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
.