4.4 Building the Example

If the entire example source code for this chapter was saved in a plain text file, called readPort.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=16f18446 -Wl,-presetVec=0h -Wa,-a -Wl,-Map=readPort.map readPort.S

The psect containing the reset code has been linked to address 0. The command also includes the options to generate a map (readPort.map). The option, -Wa,-a, requests that an assembly list file be produced, so you can explore the generated code. This option creates the list file with the same base name as the first source file present in the command line and with the extension, .lst. The above command will generate a list file called readPort.lst.

To have the linker to automatically truncate addresses when building, as discussed in Working with Data Banks, use a command line similar to:
pic-as -mcpu=16f18446 -Wl,-presetVec=0h -Wa,-a -Wl,-Map=readPort.map -Wl,--fixupoverflow=ignore readPort.S
where the linker has been instructed by the highlighted option to truncate values to fit the instruction operand width without warning. The assembler's default action if the -Wl,--fixupoverflow option is absent is to truncate values to fit the instruction operand width and insert a warning marker into the assembly list file where any overflow occurred. This action can be explicitly requested using the option -Wl,--fixupoverflow=lstwarn. This option can be added as Custom linker options, as described below, if you are using the MPLAB X IDE.

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.