Technical Note 27787
How to place a constant at specific address in code memory
||"@" / #pragma locate, constant
||April 20, 2000
1) Why can I not use #pragma locate and/or the"@" syntax for constant variables?
Regarding the "@" and the #pragma locate syntax for located variables - located variables can not
be initialized when defining them, thus it is not very useful for const variables. This is true up to and including v2.00A
of ICCPIC (Spring 2000), the special case of constant and located variables may be handled better in future versions.
2) How can I put a constant, i.e., a RETLW #, at a specific location in code memory?
To place a RETLW constant in code memory at a specified address, you could use #pragma constseg and define a segment
of your own as the example below. Note that there is a problem with pragma constseg in ICCPIC version 1.23, this is fixed in
As a workaround for version 1.23A, you can use the assembler example below.
3) How can I put a constant, i.e., a plain number, at a specific location in code memory?
This is useful only for chips with table read. Suggested way is to use assembly, as the example below.
Examples of how to define constants in code memory:
-- Assembler file
extern unsigned int __rtable myasmconst1;
extern const unsigned char myasmconst2;
const unsigned char mycconst=0x12;
-- Corresponding lines to add to copy of linker xcl-file (example for 17c756)