Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル
製品コード
SW006021-1
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 252
2012 Microchip Technology Inc.
Any address offset added to $ has the native addressability of the target device. So for
baseline and mid-range devices, the offset is the number of instructions away from the
current location, as these devices have word-addressable program memory. For PIC18
instructions, which use byte addressable program memory, the offset to this symbol
represents the number of bytes from the current location. As PIC18 instructions must
be word aligned, the offset to the location counter should be a multiple of 2. All offsets
are rounded down to the nearest multiple of 2. For example:
baseline and mid-range devices, the offset is the number of instructions away from the
current location, as these devices have word-addressable program memory. For PIC18
instructions, which use byte addressable program memory, the offset to this symbol
represents the number of bytes from the current location. As PIC18 instructions must
be word aligned, the offset to the location counter should be a multiple of 2. All offsets
are rounded down to the nearest multiple of 2. For example:
GOTO $+2 ;skip...
MOVLW 8 ;to here for PIC18 devices, or
MOVWF _foo ;to here for baseline and mid-range devices
will skip the MOVLW instruction on baseline or mid-range devices. On PIC18 devices,
GOTO $+2
GOTO $+2
will jump to the following instruction; i.e., act like a NOP instruction.
6.4.6.4
REGISTER SYMBOLS
Code in assembly modules may gain access to the special function registers by includ-
ing pre-defined assembly header files. The appropriate file can be included by add the
line:
ing pre-defined assembly header files. The appropriate file can be included by add the
line:
#include <xc.inc>
to the assembler source file. Note that the file must be included using a C pre-processor
directive and hence the option to preprocess assembly files must be enabled when
compiling, see Section 4.8.11 “-P: Preprocess Assembly Files”. This header file
contains appropriate commands to ensure that the header file specific for the target
device is included into the source file.
directive and hence the option to preprocess assembly files must be enabled when
compiling, see Section 4.8.11 “-P: Preprocess Assembly Files”. This header file
contains appropriate commands to ensure that the header file specific for the target
device is included into the source file.
These header files contain EQU declarations for all byte or multi-byte sized registers
and #define macros for named bits within byte registers.
and #define macros for named bits within byte registers.
6.4.6.5
SYMBOLIC LABELS
A label is a symbolic alias which is assigned a value equal to the current address within
the current psect. Labels are not assigned a value until link time.
the current psect. Labels are not assigned a value until link time.
A label definition consists of any valid assembly identifier followed by a colon, :. The
definition may appear on a line by itself or be positioned before a statement. Here are
two examples of legitimate labels interspersed with assembly code.
definition may appear on a line by itself or be positioned before a statement. Here are
two examples of legitimate labels interspersed with assembly code.
frank:
MOVLW 1
GOTO fin
simon44: CLRF _input
Here, the label frank will ultimately be assigned the address of the MOVLW instruction,
and simon44 the address of the CLRF instruction. Regardless of how they are defined,
the assembler list file produced by the assembler will always show labels on a line by
themselves.
and simon44 the address of the CLRF instruction. Regardless of how they are defined,
the assembler list file produced by the assembler will always show labels on a line by
themselves.
Note that the colon following the label is mandatory for PIC18 assembly, but is recom-
mended in assembly for all other devices. Symbols which are not interpreted as instruc-
tions are assumed to be labels. Mistyped assembly instructions can sometimes be
treated as labels without an error message being issued. Thus the code:
mended in assembly for all other devices. Symbols which are not interpreted as instruc-
tions are assumed to be labels. Mistyped assembly instructions can sometimes be
treated as labels without an error message being issued. Thus the code:
mistake:
MOVLW 23h
MOVWF 37h
REUTRN ; oops
defines a symbol called REUTRN, which was intended to be the RETURN instruction.
This cannot occur with PIC18 assembly code as the colon is mandatory; the compiler
would report an error when reached the line containing REUTRN.
This cannot occur with PIC18 assembly code as the colon is mandatory; the compiler
would report an error when reached the line containing REUTRN.