Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 173
5.5.3
Variables in Program Space
The only variables that are placed into program memory are those that are not auto 
and which have been qualified const. Any auto variables qualified const are placed 
in the compiled stack along with other auto variables, and all components of the com-
piled stack will only ever be located in the data space memory.
Any const-qualified (auto or non-auto) variable will always be read-only and any 
attempt to write to these in your source code will result in an error being issued by the 
compiler.
On some 8-bit PIC devices, the program space is not directly readable by the device. 
For these devices, the compiler stores data in the program memory by means of RETLW 
instructions which can be called, and which will return a byte of data in the W register. 
The compiler will generate the code necessary to make it appear that program memory 
is being read directly.
Enhanced mid-range PIC devices can directly read their program memory, although 
the compiler will still usually store data as RETLW instructions. This way the compiler 
can either produce code that can call these instructions to obtain the program memory 
data as with the ordinary mid-range devices, or directly read the operand to the instruc-
tion (the LSB of the RETLW instruction). The most efficient access method can be 
selected by the compiler when the data needs to be read.
Data can be stored as individual bytes in the program memory of PIC18 devices. This 
can be read using table read instructions.
On all devices, accessing data located in program memory is much slower than 
accessing objects in the data memory. The code associated with the access is also 
larger.
A const object is usually defined with initial values, as the program cannot write to 
these objects at runtime. However, this is not a requirement. An uninitialized const 
object can be defined to define a symbol, or label, but not make a contribution to the 
output file. Uninitialized const objects are often made absolute, see 
Section 5.5.4 “Absolute Variables”. Here are examples of const object definitions.
const char IOtype = ’A’;  // initialized const object
const char buffer[10];    // I just define a label
The data held by non-auto const variables is placed in one of several psects, based 
on the target device. See Section 5.15.2 “Compiler-Generated Psects” for the 
limitations associated with where these psects can be linked.
SeSection 5.12.3 “Interaction Between Assembly and C Code” for the equivalent 
assembly symbols that are used to represent const-qualified variables in program 
memory.