Hardware Reference
In-Depth Information
The HCS12 has dedicated instructions for making the subroutine call. The subroutine call
instruction saves the return address, which is the address of the instruction immediately fol-
lowing the subroutine call instruction, in the system stack. When completing the computation
task, the subroutine will return to the instruction immediately following the instruction that
makes the subroutine call. This is achieved by executing a return instruction, which will re-
trieve the return address from the stack and transfer the CPU control to it.
The HCS12 provides three instructions ( bsr, jsr , and call ) for making subroutine calls and
two instructions for returning from a subroutine. The syntax and operations performed by these
instructions are as follows:
bsr <opr>: bsr stands for branch subroutine. This instruction requires the user to
use the relative addressing mode to specify the subroutine to be called. When
this instruction is executed, the stack pointer is decremented by 2 and the return
address is saved in the stack; then the offset in the instruction is added to the
current PC value and instruction execution is continued from there. In assembly
language, the relative address is specified by using a label, and the assembler will
figure out the relative offset and place it in the program memory. For example, the
following instruction calls the subroutine bubble:
bsr bubble
jsr <opr>: jsr stands for jump subroutine. The user can use direct, extended,
indexed, and indexed indirect addressing modes to specify the subroutine to be
called. The subroutine can be located anywhere within 64 kB. As with the bsr
instruction, the HCS12 first saves the return address in the stack and then jumps
to execute the subroutine. Examples of the jsr instruction are as follows:
jsr
$ff
; call the subroutine located at $ff
jsr
sq_root
; call the subroutine sq_root
jsr 0,x ; call a subroutine pointed to by index register X
call <opr>: This instruction is designed to work with expanded memory (larger than
64 kB) supported by some HCS12 members. Members with expanded memory treat
the 16-kB memory space from $8000 to $BFFF as a program memory window. An
8-bit program page register (PPAGE) is added to select one of the 256 16-kB program
memory pages to be accessed. To support subroutine calls in expanded memory, the
call instruction pushes the current value of the PPAGE register along with the return
address onto the stack and then transfers program control to the subroutine (3 bytes
are pushed into the stack). The <opr> field in the call instruction specifies the page
number and the starting address of the subroutine within that page. The new page
number will be loaded into the PPAGE register when the call instruction is executed.
Extended, indexed, and indexed indirect addressing modes can be used to specify the
subroutine address within a page. Writing assembly programs to be run in expanded
memory requires an assembler that supports this feature.
rts: rts stands for return from subroutine . This instruction pops the 16-bit value
from the stack onto the program counter and increments the stack pointer by 2.
Program execution continues at the address restored from the stack. This
instruction is used with the jsr and bsr instructions.
rtc: rtc stands for return from call . This instruction terminates subroutines in
expanded memory invoked by the call instruction. The program page register and
the return address are restored from the stack; program execution continues at the
restored address. For code compatibility, call and rtc are also executed correctly by
 
Search WWH ::




Custom Search