Allocation of Executable Code

Code associated with functions is always placed in program memory.

On Baseline and Mid-range devices, the program memory is paged. Program memory addresses are still sequential across a page boundary, but the paging means that calls or jumps from code in one page to a label in another must use a longer sequence of instructions. Your device data sheet has more information on the program memory and instruction set for your device.

PIC18 devices do not implement any program memory paging. The call and goto instruction are two-word instructions and their destinations are not limited.

The generated code associated with each function is initially placed in sections by the compiler (see Compiler-Generated Psects). When the program memory is paged, the optimizer tries to allocate several functions to the same section so they can use the shorter form of call and jump. These sections are linked anywhere in the program memory (see Main, Runtime Startup and Reset), although Baseline devices restrict the entry point of functions to within the first 256 location in each page.

The base name of each section is tabulated below. See Program Space Psects for a full list of all program-memory section names.

maintext
The generated code associated with the special function, main(), is placed in this section. Some optimizations and features are not applied to this psect.
textn
These sections (where n is a decimal number) contain all other executable code that does not require a special link location.