4.6 Code Directive
The MPASM CODE
directive starts a section containing program
code.
Suggested Replacement
Use the predefined code
psect, or a create a similar
psect, ensuring the flags are suitable for a section containing executable code on
the target device. If the psects must be padded to a multiple of a certain size, use
the ALIGN
directive after the code you place inside the psect.
PSECT
directive. The PIC Assembler provides the
code
psect once you include
<xc.inc>
. You can use this psect
without having to specify any psect flags, for
example:PSECT code
;place code for any device here
Alternatively, you can define your own psect with any name and suitable
psect flags. The psect's space
flag must be 0, to indicate that the
psect should be positioned in program memory; however, this is the default value.
Typically, you would use the class
flag to assign the psect to the
CODE
linker class, which is also predefined by the driver, so
that the psect will be positioned somewhere in the memory associated with this class
without you having to specify any linker options. You could also position this psect
at a particular address using the linker's -p
option, passed to the
linker from the driver's -Wl
option.
reloc
flag to be 2,
to indicate that the psect contents must be aligned on even addresses. Use the
default delta
value of 1. For
example:PSECT myText,reloc=2,class=CODE
;PIC18 code goes here
For all other devices, use the default reloc
flag value
of 1, but set the delta
value to be 2, to indicate that the device
uses (16-bit) word addressable program memory. For example:
PSECT myText,delta=2,class=CODE
;Baseline/Mid-range code goes here
PSECT
directive with the psect's name, but you do not
need to repeat the psect flags. You could, for example, concatenate more content to
the psects defined above by
using:PSECT myText
;more content goes here