Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル
製品コード
SW006021-1
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 206
2012 Microchip Technology Inc.
If you wish to access register definitions from assembly that is inline with C code, a dif-
ferent header file is available for this purpose. Include the header file <caspic.h> into
the assembly code. This file can only be used with baseline and mid-range devices.
There is non comparable file for PIC18 devices.
ferent header file is available for this purpose. Include the header file <caspic.h> into
the assembly code. This file can only be used with baseline and mid-range devices.
There is non comparable file for PIC18 devices.
The symbols used for register names will be the same as those defined by <xc.inc>;
however, the names assigned to bit variables within the registers will include the suffix
_bit
however, the names assigned to bit variables within the registers will include the suffix
_bit
. So for example, the example given previously could be rewritten as inline
assembly as follows.
#asm
MOVLW
0xAA
BANKSEL
(PORTA)
MOVWF
BANKMASK(PORTA)
BANKSEL
(PORTB)
BSF
RB1_bit
#endasm
Care must be taken to ensure that you do not destroy the contents of registers that are
holding intermediate values of calculations. Some registers are used by the compiler
and writing to these registers directly can result in code failure. The code generator
does not detect when SFRs have changed as a result of assembly code that writes to
them. The list of registers used by the compiler and further information can be found in
Section 5.7 “Register Usage”.
holding intermediate values of calculations. Some registers are used by the compiler
and writing to these registers directly can result in code failure. The code generator
does not detect when SFRs have changed as a result of assembly code that writes to
them. The list of registers used by the compiler and further information can be found in
Section 5.7 “Register Usage”.
5.12.3.3
ABSOLUTE PSECTS
Some of the information that is extracted from the initial compilation of assembly code,
see Section 4.3.4 “Compilation of Assembly Source”, relates to absolute psects,
specifically psects defined using the abs and ovrld, PSECT flags, see
Section 6.4.9.3 “PSECT” for information on this directive.
see Section 4.3.4 “Compilation of Assembly Source”, relates to absolute psects,
specifically psects defined using the abs and ovrld, PSECT flags, see
Section 6.4.9.3 “PSECT” for information on this directive.
MPLAB XC8 is able to determine the address bounds of absolute psects and uses this
information to ensure that the code produced from C source by the code generator
does not use memory required by the assembly code. The code generator will reserve
any memory used by the assembly code prior to compiling C source.
information to ensure that the code produced from C source by the code generator
does not use memory required by the assembly code. The code generator will reserve
any memory used by the assembly code prior to compiling C source.
Here is an example of how this works. An assembly code files defines a table that must
be located at address 0x110 in the data space. The assembly file contains:
be located at address 0x110 in the data space. The assembly file contains:
PSECT lkuptbl,class=RAM,space=1,abs,ovlrd
ORG 110h
lookup:
DS 20h
An absolute psect always starts at address 0. For such psects, you can specify a
non-zero starting address by using the ORG directive. See Section 6.4.9.4 “ORG” for
important information on this directive.
non-zero starting address by using the ORG directive. See Section 6.4.9.4 “ORG” for
important information on this directive.
When the project is compiled, this file is assembled and the resulting relocatable object
file scanned for absolute psects. As this psect is flagged as being abs and ovlrd, the
bounds and space of the psect will be noted — in this case, a memory range from
address 0x110 to 0x12F in memory space 1 is noted as being used. This information is
passed to the code generator to ensure that this address range is not used by the
assembly generated from the C code.
file scanned for absolute psects. As this psect is flagged as being abs and ovlrd, the
bounds and space of the psect will be noted — in this case, a memory range from
address 0x110 to 0x12F in memory space 1 is noted as being used. This information is
passed to the code generator to ensure that this address range is not used by the
assembly generated from the C code.
The linker handles all of the allocation into program memory, and so for hand-written
assembly, only the psects located in data memory need be defined in this way.
assembly, only the psects located in data memory need be defined in this way.