8.3 Building the Example

If the source code shown in this chapter was saved in a plain text file, called timedLED.S, for example, it could be built using the command below. Note that the file name uses an upper case .S extension so that the file is preprocessed before any other processing.
pic-as -mcpu=18F47K42 -Wl,-presetVec=0h -Wl,-pivt=08h -Wa,-a -Wl,-Map=timedLED.map timedLED.S

The ivt psect holding the vector table was linked to address 0x8. The link address of this psect is used in the source code to load the value contained in the IVTBASE register, to ensure that the device reads the correct vectors when an interrupt occurs. The address you specify for this psect must be a multiple of two to ensure the requirement imposed by the reloc flag used with this psect is met. If you were to attempt to link the psect at an odd address, an error will be issued.

The above command also includes the -Wl,-Map=timedLED.map option to generate a map file and the -Wa,-a option to generate an assembly list file, which will be called timedLED.lst.

If you are building in the MPLAB X IDE, add additional linker options (such as those specified using the driver option -Wl,linkerOption) to the Custom linker options field in the pic-as Linker > general category in the Project Properties dialog. When adding options to this field, do not include the leading -Wl,, as this prefix is added in by the IDE. Specify additional options to the assembler (such as the -Wa,assemblerOption) in the Additional options field in the pic-as Global Options category (the leading -Wa, must be specified). See Building the Example for screen captures showing where these additional options should be added.