227/317
8 - C Language and the C Compiler
The availa ble m emory varies with the mode l of S T7 chose n. T o o ptim ize the access to
memory, the compiler offers four memory models that set the rules for data allocation. These
models are:
These modes govern the default selections; however, it is still possible in all models to depart
from them using appropriate segment specifications, as mentioned below. To alter the alloca-
tion mechanism, controls are provided to suit the user's needs in some special cases. Here
are some of these cases:
8.3.1.1 Read-only constants
By default, all variables are allocated in RAM. According to the syntax of C, any variable may
be given an initial value. This initial value is automatically stored in ROM by the compiler, and
an initialization routine copies the contents of the ROM to the RAM before the user program is
started.
In many cases, some variables are only read by the program, but never written to: they are ac-
tually constants. In C, unlike Pascal or other languages, constants do not exist. Instead, the
modifier
const
may be applied to a regular variable declaration for the same purpose. It is
used as follows:
const int SIZE = 100 ;
Model name
Local data
Global data
Effect
Small
direct
direct
Data are referenced using direct addressing or
near
pointers, except constant data that are accessed through
extended addressing and/or
far
pointers. Only for small
applications.
Small extend-
ed
extended
direct
Same as above, but local data is located above 100h and
thus accessed using extended addressing.
Large
direct
extended
Local data is located in page zero, and global data is put
above 100h and accessed using extended addressing.
This is the default mode, since it is generally the most ju-
dicious.
Large Extend-
ed
extended
extended
This mode assumes there is a large amount of both local
and global data. It is probably irrelevant with the currently
available ST7 products.