(XC16) How can I utilize the upper 8-bits of program memory to effectively store constants?

The qualifier __pack_upper_byte will allocate the message string into Flash memory in such a way that the upper byte of memory contains valid data. There are no restrictions on the types of __pack_upper_byte data. This qualifier can be used with both the primary data types as well as the secondary data types.

The compiler will "pack" structures as if __attribute__((packed)) had been specified.


Memory Allocation Without __pack_upper_byte (string_un_packed):

Address Value ASCII
00A08 BE054F BE044F 060000 006854 O...O... ....Th..
00A10 007369 006920 002073 002061 is.. i.. s ..a ..
00A18 007473 006972 00676E 00002E st..ri.. ng......

Memory Allocation With __pack_upper_byte (string_packed):

Address Value ASCII
00D30 696854 692073 612073 747320 Thi.s i. s a. st.
00D38 6E6972 002E67 FFFFFF FFFFFF rin.g... ........
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.