Reserving Memory

Last modified by Microchip on 2024/02/06 09:29

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