Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 201
SeSection 6.4.9.3 “PSECT” for detailed information on the flags used with the 
PSECT
 assembler directive. This psect is called text0. It is flagged local, which 
means that it is distinct from other psects with the same name. This flag is not important 
in this example and can be omitted, if required. It lives in the CODE class. This flag is 
important as it means it will be automatically placed in the area of memory set aside for 
code. With this flag in place, you do not need to adjust the default linker options to have 
the psect correctly placed in memory. The last option, the delta value, is also very 
important. This indicates that the memory space in which the psect will be placed is 
word addressable (value of 2). The PIC10/12/16 program memory space is word 
addressable; the data space is byte addressable.
For PIC18 devices, program memory is byte addressable, but instructions must be 
word-aligned, so you will see code such as the following.
PSECT text0,local,class=CODE,reloc=2
In this case, the delta value is 1 (which is the default setting), but the reloc (align-
ment) flag is set to 2, to ensure that the section starts on a word-aligned address.
We simply need to choose a different name, so we might choose the name mytext, 
as the psect name in which we will place out routine, so we have for our mid-range 
example:
PSECT mytext,local,class=CODE,delta=2
Let’s assume we would like to call this routine add in the C domain. In assembly 
domain we must choose the name _add as this then maps to the C identifier add. If we 
had chosen add as the assembly routine, then it could never be called from C code. 
The name of the assembly routine is the label that we will place at the beginning of the 
assembly code. The label we would use would look like this.
_add:
We need to be able to call this from other modules, so make this label globally acces-
sible, by using the GLOBAL assembler directive (Section 6.4.9.1 “GLOBAL”).
GLOBAL _add
By compiling a dummy C function with a similar prototype to this assembly routine, we 
can determine the signature value. The C-equivalent prototype to this routine would 
look like:
unsigned char add(unsigned char);
Check the assembly list file for the signature value of such a function. You will need to 
turn the assembler optimizer off for this step, as the optimizer removes these values 
from the assembly list file. Signature values are not mandatory, but allow for additional 
type checking to be made by the linker. We determine that the following SIGNAT direc-
tive (Section 6.4.9.21 “SIGNAT”) can be used.
SIGNAT _add,4217
The W register will be used for passing in the argument. SeSection 5.8.6 “Function 
Parameters”
 fo
r the convention used to pass parameters.