Runtime
Environment
-
Memory
Model
5.1.5
Allocating
Memory
for
Static
and
Global
Variables
A unique,
contiguous
space
is
allocated in the .bss section
for
each external
or
static variable that
is
declared in a C program. The linker determines the
address
of
the global variables
when
it
allocates the .bss section. The compiler
ensures that space for these variables
is
allocated in multiples
of
words, so that
each variable
is
aligned on a
word
boundary. You should allocate .bss
into
RAM when you
link
the program.
5.1.6
Packing
Structures
and
Manipulating
Fields
When the compiler allocates space for a structure, it allocates the exact
amount
of
memory needed
to
contain all
of
the structure's members. Fields
are
allocated
as
many bits
as
requested; enumerated types
are
allocated
as
few
bits
as
possible
to
hold the maximum value
of
that type; bytes
are
allocated
eight bits, and so on.
The C compiler
follows
standard C practice for mapping structures,
with
one
exception: a
field
of
width
zero does
not
force
word
alignment. Because
of
the
TMS34010's
bit-addressability,
word
alignment in a structure does
not
necessarily produce more efficient code. However, a field that straddles
word
boundaries does take longer
to
access, since the TMS3401 0 must fetch more
than one word. You should be very careful
when
you're defining structures
or arrays
of
structures; try
to
avoid defining fields that cross
word
boundaries.
If
a structure
is
declared
as
an
external or static variable,
it
is
always placed
on a
word
boundary and is allocated space rounded
up
to
a
word
boundary.
However, when
an
array
of
structures
is
declared, no rounding
of
size
is
used;
exactly enough space
is
allocated
to
hold each structure element
in
contig-
uous bits
of
memory.
5.1.7
Array
Alignment
In
ANSI
standard
C,
as
well
as
K&R
C,
arrays
are
expected
to
always align their
elements on a
word
boundary,
with
the exception
of
bytes,
which
may be
aligned on a byte boundary. The
TMS34010's
bit-addressability makes this
restriction
both
unimportant and inefficient; so, in
TMS34010
C,
arrays have
no internal alignment.
Each
array element
is
allocated exactly
as
much space
as
needed,
with
no
space between adjacent elements.
Note:
Like structures, a carefully defined array
(with
no elements overlapping
word
boundaries)
will
allow
the program
to
run faster. Pixel arrays
are
usually aligned in this manner.
If
an
array
is
declared
as
an
external
or
static variable, the first element
of
the
array
is
placed on a
word
boundary and the array
is
allocated space rounded
up
to
a
word
boundary.
This method
of
handling
an
array allows more control over the environment
than standard C
allows. Bit arrays and pixel arrays are directly accessible (a
necessity
for
a graphics environment), and memory-mapped
I/O
is more
straightforward.
5-5