Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 184
 2012 Microchip Technology Inc.
in one page to a label in another must use a longer sequence of instructions to accom-
plish this. See your device data sheet for more information on the program memory and 
instruction set.
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 relative 
branch instructions have a limited range, but this is not based on any paging boundar-
ies.
The generated code associated with each function is initially placed in its own psect by 
the compiler, see Section 5.15.1 “Program Sections”. These psects have names 
such as textn, where n is a number, e.g., text98. However, psects may be merged 
later in the compilation process so that more than one function may contribute to a 
psect.
When the program memory us paged, functions within the same psect can use a 
shorter form of call and jump to labels so it is advantageous to merge the code for as 
many functions into the same psect. These text psects are linked anywhere in the pro-
gram memory (see 5.10 “Main, Runtime Startup and Reset”).
If the size of a psect that holds the code associated with a function exceeds the size of 
a page, it may be split by the assembler optimizer. A split psect will have a name of the 
form textn_split_s. So, for example, if the text102 psect exceeds the size of a 
page, it may be split into a text102_split_1 and a text102_split_2 psect. This 
process is fully automatic, but you should be aware that if the code associated with a 
function does become larger than one page in size, the efficiency of that code may drop 
fractionally due to any longer jump and call instruction sequences being used to trans-
fer control to code in other pages.
The base name of each psect category is tabulated below. A full list of all pro-
gram-memory psects psect names are listed in Section 5.15.2.1 “Program Space 
Psects”
.
maintext
 The generated code associated with the special function, main, is placed 
in this psect. Some optimizations and features are not applied to this psect.
textn
 These psects (where n is a decimal number) contain all other executable code 
that does not require a special link location.
5.8.4
Changing the Default Function Allocation
If you only intend to prevent functions from using one or more program memory loca-
tions so that you can use those locations for some other purpose, you are best reserv-
ing the memory using the memory adjust options. See Section 4.8.49 “--ROM: Adjust 
ROM Ranges”
 for information on how to do this.
The assembly code associated with a C function can be placed at an absolute address. 
This can be accomplished by using an @ address construct in a similar fashion to 
that used with absolute variables. Such functions are called absolute functions.
The following example of an absolute function will place the function at address 400h:
int mach_status(int mode) @ 0x400
{
/* function body */
}
If you check the assembly list file you will see the function label and the first assembly 
instruction associated with the function located at 0x400. You can use either the 
assembly list file (see 6.5 “Assembly-Level Optimizations”) or the map file (see 
7.4 “Map Files”) to confirm that the function was moved as you expect.