
Application Note
AN1218 Rev. 2
18
* Subroutine XX for CPU05 *
START
STX
STA
$50
$51
;4 store X away to RAM
;4 store A away to RAM
XX
XX
XX
XX
;actual subroutine code
LDX
LDA
$50
$51
;3 load X from RAM
;3 load A from RAM
Figure 4. CPU05 Subroutine Code
TheCPU05codewilluse14cyclestostoreandloadregisters. Also,two
bytes of global RAM space are allocated for this subroutine. If we were
to use the CPU08, the code could utilize the stack. Global RAM space
and six cycles would be saved. Refer to
Figure 5
.
* Subroutine XX for CPU08 *
START
PSHX
PSHH
PSHA
;2 push X onto stack
;2 push H onto stack
;2 push A onto stack
XX
XX
XX
XX
;actual subroutine code
PULA
PULH
PULX
;2 pull A off of stack
;2 pull H off of stack
;2 pull X off of stack
Figure 5. CPU08 Subroutine Code
The stack helps in efficiently utilizing parameters, local variables, and
subroutine return values. Parameters are variables that are passed to
the subroutine. Local variables are variables that are only used within
the scope of the subroutine. A subroutine return value is the output of
the subroutine. An example of a subroutine and its variables are given
below in equation form:
Y = (X)3
If we were to write a subroutine that calculates the cube of the value X,
X would be the parameter passed to the subroutine. Y would be the
subroutine return value, and any variable used to calculate Y would be
F
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
.