dsp56800 Freescale Semiconductor, Inc, dsp56800 Datasheet - Page 214

no-image

dsp56800

Manufacturer Part Number
dsp56800
Description
16-bit Digital Signal Controllers
Manufacturer
Freescale Semiconductor, Inc
Datasheet
Software Techniques
8.8
The DSP56800 software stack supports structured programming techniques, such as parameter passing to
subroutines and local variables. These techniques can be used for both assembly language programming
and high-level language compilers.
Parameters can be passed to a subroutine by placing these variables on the software stack immediately
before performing a JSR to the subroutine. Placing these variables on the stack is referred to as building a
“stack frame.” These passed parameters are then accessed in the called subroutines using the stack
addressing modes available on the DSP56800. This is demonstrated in the following example (which
destroys the x0 register):
; Example of Subroutine Call With Passed Parameters
ROUTINE1:
;
;
In a similar manner it is also possible to allocate space and to access variables that are locally used by a
subroutine, referred to as local variables. This is done by reserving stack locations above the location that
stores the return address stacked by the JSR instruction. These locations are then accessed using the
DSP56800’s stack addressing modes. For the case of local variables, the value of the stack pointer is
updated to accommodate the local variables. For example, if five local variables are to be allocated, then
the stack pointer is increased by the value of five to allocate space on the stack for these local variables.
When large numbers of variables are allocated on the stack, it is often more efficient to use the (SP)+N
addressing mode.
It is possible to support passed parameters and local variables for a subroutine at the same time. In this case
the program first pushes all passed parameters onto the stack (see Figure 8-1) using the technique outlined
in Section 8.5, “Multiple Value Pushes.” Then the JSR instruction is executed, which pushes the return
address and the SR onto the stack. Upon being entered, the subroutine first allocates space for local
variables by updating the SP. Then, both passed parameters and local variables can be accessed with the
stack addressing modes.
8-28
MOVE
LEA
MOVE
MOVE
MOVE
MOVE
MOVE
JSR
POP
POP
POP
MOVE
LEA
(instructions)
MOVE
MOVE
MOVE
ADD
MOVE
(instructions)
MOVE
LEA
RTS
Parameters and Local Variables
X:$35,X0
(SP)+
X0,X:(SP)+
X:$21,X0
X0,X:(SP)+
X:$47,X0
X0,X:(SP)
ROUTINE1
#5,N
(SP)+N
X:(SP-9),r0
X:(SP-7),B
X:(R0),X0
X0,B
B,X:(SP-8)
#-5,N
(SP)+N
; Pointer variable to be passed to subroutine
; Push variables onto stack
; First data variable to be passed to subroutine
; Push onto stack
; Second data variable to be passed to
; subroutine
; Push onto stack
; Remove the three passed parameters from
; stack when done
; Allocate room for local variables
; Get pointer variable
; Get second data variable
; Get data pointed to by pointer variable
; Store sum in first data variable
DSP56800 Family Manual
Freescale Semiconductor

Related parts for dsp56800