Software Project Management
Sections And Data Hiding
4-4
DSP ASSEMBLER REFERENCE MANUAL
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
4.3.2
Sections and Macros
The division of a program into sections controls not only labels and symbols, but also mac-
ros and
DEFINE
directive symbols. Macros defined within a section are private to that
section and are distinct from macros defined in other sections even if they have the same
macro name. Macros defined outside of sections are considered global and may be used
within any section. Similarly,
DEFINE
directive symbols defined within a section are pri-
vate to that section and
DEFINE
directive symbols defined outside of any section are glo-
bally applied. There are no directives that correspond to
XDEF
for macros or
DEFINE
symbols, therefore macros and
DEFINE
symbols defined in a section can never be ac-
cessed globally. If global accessibility is desired, the macros and
DEFINE
symbols should
be defined outside of any section. Here is an example:
DEFINE
SECTION
DEFINE
MOVE
ENDSEC
MOVE
DEFVAL
SECT1
DEFVAL
#DEFVAL,R0
'1'
'2'
#DEFVAL,R1
The second definition of DEFVAL is visible only inside SECT1, so the value moved to R0
will be 2. However, the second move instruction is outside the scope of SECT1 and will
therefore use the initial definition of DEFVAL. This means that the value 1 will be moved
to R1.
4.3.3
Nested and Fragmented Sections
Sections can be nested to any level. When the Assembler encounters a nested section,
the current section is stacked and the new section is used. When the
ENDSEC
directive
of the nested section is encountered, the Assembler restores the old section and uses it.
The
ENDSEC
directive always applies to the most recent
SECTION
directive. Nesting
sections provides a measure of scoping for symbol names, in that symbols defined within
a given section are visible to other sections nested within it. For example, if section B is
nested inside section A, then a symbol defined in section A can be used in section B with-
out
XDEF
ing in section A or
XREF
ing in section B. This scoping behavior can be turned
off and on with the
NONS
and
NS
options respectively (see the
OPT
directive, Chapter 6).
Sections may also be split into separate parts. That is, <section name> can be used mul-
tiple times with
SECTION
and
ENDSEC
directive pairs. If this occurs, then these separate
(but identically named) sections can access each others symbols freely without the use of
the
XREF
and
XDEF
directives. If the
XDEF
and
XREF
directives are used within one
section, they apply to all sections with the same section name. The reuse of the section
name is allowed to permit the program source to be arranged in an arbitrary manner (for
example, all statements that reserve X space storage locations grouped together), but re-
tain the privacy of the symbols for each section.
F
Freescale Semiconductor, Inc.
n
.