Technical information
AN2216/D
6 MC9S12DP256 Software Development Using Metrowerk’s Codewarrior MOTOROLA
Data Segment
#pragma DATA_SEG [SHORT] <segment_name>
#pragma DATA_SEG specifies a segment for global data variables. This
includes both variable and constant data by default. Constant data may be
assigned to a specific segment by means of the #pragma CONST_SEG
described below. The only relevant attribute for DATA_SEG for the
MC9S12DP256 is SHORT. This specifies that the direct addressing mode is
used to access the variable. A SHORT segment must therefore be allocated to
memory on the range $0000 to $00FF. If the attribute is omitted then normal
addressing modes other than direct will be used. If no segment is specified, the
data will be assigned to the default segment DEFAULT_RAM. To explicitly
assign the default segment, use the segment name DEFAULT. All global
variables following the #pragma DATA_SEG statement are included in the
segment until the next #pragma DATA_SEG statement. Thus assignment of
the default segment is a convenient means of terminating a specific segment:
#pragma DATA_SEG DEFAULT
Any declarations of external data variables must be within the same data
segment as the data variable definition itself. Thus if var1 is defined in data
segment A in a file, any other files which contain code which accesses var1
would contain the declaration:
#pragma DATA_SEG A
extern int var1;
#pragma DATA_SEG DEFAULT
Constants Segment
#pragma CONST_SEG [PPAGE] <segment_name>
#pragma CONST_SEG defines a segment for constant global data variables.
The only relevant attribute for the MC9S12DP256 is PPAGE. This specifies that
the constant data variables will be accessed by manipulation of the PPAGE
register. This is required if constant data variables will be located in paged
memory. The manipulation of the PPAGE register will be performed by a
runtime routine and this is specified to the compiler with the option
–CpPpage=RUNTIME on the compiler command line. If no attribute is
specified, the compiler assumes that the data variables will be accessed
without manipulation of any page register, i.e. the data variables will be
allocated to non-paged memory. If no segment is specified, constant data will
be assigned to the default segment ROM_VAR. To explicitly assign the default
segment for constant data, use the segment name DEFAULT. This assigns