5.4 Building the Example
file_1.S
and file_2.S
, they could both be built
using the single command
below.pic-as -mcpu=16f18446 -Wl,-presetVec=0h -DNUM_TO_READ=100 -Wa,-a -Wl,-Map=linearMemory.map file_1.S file_2.S
In this command, the psect containing the reset code has been linked to address 0. The
command also includes the option to generate a map file called
linearMemory.map
. The -Wa,-a
option requests an
assembly list file. One list file will be produced for each source module and the above
command will generate files called file_1.lst
and
file_2.lst
.
The preprocessor macro NUM_TO_READ
, which determines the size of the
linear array and the number of values stored, has been defined as 100 using the
-D
option. Defining this on the command line rather than using
#define
directives means that the macro can be more easily used in
every source file. It also lets you change the value associated with the macro without
having to modify your source code.
pic-as -mcpu=16f18446 -Wa,-a -c -DNUM_TO_READ=100 file_1.S
pic-as -mcpu=16f18446 -Wa,-a -c -DNUM_TO_READ=100 file_2.S
pic-as -mcpu=16f18446 -Wl,-presetVec=0h -Wl,-Map=linearMemory.map file_1.o file_2.o
Here, the -c
option has been used to generate an intermediate file for
each source file. The intermediate (object) files will have a .o
extension. The final command links the object files and produces the final output. Note
that the option to create the assembly list file is required with the first two assembly
commands, as is the -D
option that defines the preprocessor macro. The
option to create the map files is only needed with the final build command. The
-mcpu
option, which indicates the target device, must be used with
every command.
The MPLAB X IDE performs incremental builds of each source file, in a similar way to the multi-step command-line example, above.
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 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.
To specify the -D
option, enter NUM_TO_READ=100
in the
Define preprocessor symbol field in the category.