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

製品コード
SW006021-1
ページ / 518
How To’s
 2012 Microchip Technology Inc.
DS52053B-page 55
• You must ensure that the address of the RAM variable you are accessing has 
been masked so that only the bank offset is being used as the instruction’s file 
register operand. This should not be done if you are using an instruction that takes 
a full address (such as the MOVFF instruction on PIC18 devices). Check your 
device data sheet to see what address operand instructions requires. Failure to 
mask an address may lead to a fixup error (see Section 3.7.8 “How Do I Fix a 
Fixup Overflow Error?”
)
 or code failure.
The BANKMASK macro can truncate the address for you, see Section 5.12.3.2 
“Accessing Registers from Assembly Code”
.
• Before you call or jump to any routine, you must ensure that you have selected 
the program memory page of this routine using the appropriate instructions. You 
can either use the PAGESEL pseudo instruction, see Section 6.4.1.2 “Bank and 
Page Selection”
, or the FCALL or LJMP pseudo instructions (not required on 
PIC18 devices), see Section 6.4.1.4 “Long Jumps and Calls” which will auto-
matically add page selection instructions, if required.
• You must ensure that any RAM used for storage has memory reserved. If you are 
only accessing variables defined in C code, then reservation is already done by 
the compiler. You must reserve memory for any variables you only use in the 
assembly code using an appropriate directive such as DS or DABS, see 
Section 6.4.9.10 “DS” or Section 6.4.9.11 “DABS”. It is often easier to define 
objects in C code rather than in assembly.
• You must place any assembly code you write in a psect (see Section 6.4.9.3 
“PSECT” for the directive to do this anSection 5.15.1 “Program Sections” for 
general information about psects). A psect you define may need flags (options) to 
be specified. Pay particular note to the delta, space and class flags (see 
Section 6.4.9.3.4 “Delta”Section 6.4.9.3.13 “Space” and Section 6.4.9.3.3 
“Class”
). I
f these are not set correctly, compile errors or code failure will almost 
certainly result. If the psect specifies a class and you are happy with it being 
placed anywhere in the memory range defined by that class (see Section 7.2.1 
“-Aclass =low-high,...”
)
, it does not need any additional options to be linked; oth-
erwise, you will need to link the psect using a linker option (see Section 7.2.19 
“-Pspec”
 for the usual way to link psects and Section 4.8.7 “-L-: Adjust Linker 
Options Directly”
 which indicates how you can specify this option without run-
ning the linker directly).
Assembly code that is placed in-line with C code will be placed in the same psect 
as the compiler-generated assembly and you should not place this into a separate 
psect.
• You must ensure that any registers you write to in assembly code are not already 
in used by compiler-generated code. If you write assembly in a separate module, 
then this is less of an issue as the compiler will, by default, assume that all regis-
ters are used by these routines (see Section 5.7 “Register Usage”, registers). 
No assumptions are made for in-line assembly (see Section 5.12.2 “#asm, 
#endasm and asm()”
)
 and you must be careful to save and restore any 
resources that you use (write) and which are already in use by the surrounding 
compiler-generated code.