6.3 Building the Example

If this chapter's example code was saved in a plain text file, called cstack.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,-pudata_acs=COMRAM -Wa,-a -Wl,-Map=cstack.map -mcallgraph=full cstack.S

No special options are needed for a compiled stack to be assembled by the linker; a compiled stack is automatically created if FN-type directives are detected in the object files being linked.

The above command shows a -p linker option being used to place the psect used to hold the compiled stack, udata_acs, into a suitable linker class. Such an option is not usually required, but will suppress a warning that will otherwise result when the FNCONF directive is used in a program.

The -mcallgraph option has been used to request that a full callgraph be printed. The callgraph is shown in the map file, which was requested by the option -Wl,-Map=cstack.map in the above.

As with the previous examples, the psect containing the reset code has been linked to address 0. The command also includes the -Wa,-a option to generate an assembly list file (cstack.lst), so you can explore the generated code.

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.