Reserving Memory

The MPLAB® XC8 compiler has --RAM and --ROM options which allow you to adjust the default memory used when a project is built. (These are accessible in the MPLAB X IDE using the RAM ranges and ROM ranges linker fields.) Typically these options are used to reserve memory so that this space cannot be used by compiler-generated code or data. These options are flexible and there are several ways that they can be used to reserve memory, but it is better to apply the option subtractively, rather than use them to specify a subset of the default memory ranges.

For example, if a device has 2000h words of program memory and the range from 7F0h to 80Fh needs to be reserved, you could explicitly specify the available memory using the option --ROM=0-7EFh,810-1FFF; however a better approach is to simply indicate the range that needs to be removed from the default memory, as in --ROM=default,-7F0-80F.

There are several reasons why this is preferable. It can make the options easier to read and you don’t have to do the math to work out the remaining ranges. But also, subtracting from the default memory ensures that any page or bank boundaries in the memory space are preserved, along with any special memory configuration that the compiler might use, which could include other reserved locations or memory outside the normal device ranges.

© 2018 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.