
5-34
Motorola DSP56000 Family Optimizing C Compiler User’s Manual
For More Information On This Product,
Go to: www.freescale.com
Motorola
Out-of-line Assembly Code
Example 5-34. Changing a Global Label
Changing a Global Label. This example shows C code that generates a global integer
(Ginteger) which is accessed as Ginteger in both the C environment and the assembly
programming environment.
extern int Ginteger _ _asm(“Ginteger”);
Which will appear in assembly language code as:
Ginteger dc
$0
global
Ginteger
5.4.3 Using Run-time Stack for Local Data
The run-time stack may be used when the programmer requires a temporary data space for
automatic
style variables — i.e., local variables in subroutines. Using the run-time stack
requires additional steps in the prologue and epilogue sections. It is the subroutine’s
responsibility to automatically allocate and deallocate the stack at run-time.
In the prologue, an extra step is required to save the run-time stack space. Keeping in mind
that the stack pointer
must
always point to the next available stack location, the stack
space is
allocated
by advancing the stack pointer by the amount of space required. One
way to allocate this space is shown in the Section .
Example 5-35. Run-time Stack Allocation
Run-time stack allocation: This code segment can be inserted in the general template
prologue for out-of-line assembly code. Notice that “size” in the move statement below
should be replaced with the appropriate constant.
move
nop
on r6
move
locals
#size
,n6; the stack size needed
; wait until n6 is available to operate
(r6)+n6 ; allocate the run-time stack for
Referencing the data space can then be accomplished using negative offsets from the stack
pointer or via initialized address registers. There are many alternatives to these methods
but they are all similar.
In the epilogue, an extra step is required to restore the stack pointer — i.e., deallocate the
run-time local stack. This is simply the reverse of the allocation process in the prologue.
F
Freescale Semiconductor, Inc.
n
.