SLAU131Y October 2004 – June 2021
Copy Source File
.copy "filename"
.include "filename"
The .copy and .include directives tell the assembler to read source statements from a different file. The statements that are assembled from a copy file are printed in the assembly listing. The statements that are assembled from an included file are not printed in the assembly listing, regardless of the number of .list/.nolist directives assembled.
When a .copy or .include directive is assembled, the assembler:
The filename is a required parameter that names a source file. It is enclosed in double quotes and must follow operating system conventions.
You can specify a full pathname (for example, /320tools/file1.asm). If you do not specify a full pathname, the assembler searches for the file in:
For more information about the --include_path option and MSP430_A_DIR, see Section 5.6. For more information about MSP430_C_DIR, see the MSP430 Optimizing C/C++ Compiler User's Guide.
The .copy and .include directives can be nested within a file being copied or included. The assembler limits nesting to 32 levels; the host operating system may set additional restrictions. The assembler precedes the line numbers of copied files with a letter code to identify the level of copying. A indicates the first copied file, B indicates a second copied file, etc.
In this example, the .copy directive is used to read and assemble source statements from other files; then, the assembler resumes assembling into the current file.
The original file, copy.asm, contains a .copy statement copying the file byte.asm. When copy.asm assembles, the assembler copies byte.asm into its place in the listing (note listing below). The copy file byte.asm contains a .copy statement for a second file, word.asm.
When it encounters the .copy statement for word.asm, the assembler switches to word.asm to continue copying and assembling. Then the assembler returns to its place in byte.asm to continue copying and assembling. After completing assembly of byte.asm, the assembler returns to copy.asm to assemble its remaining statement.
copy.asm (source file) |
byte.asm (first copy file) |
word.asm (second copy file) |
---|---|---|
|
|
|
Listing file:
1 0000 .space 29
2 .copy "byte.asm"
A 1 ** In byte.asm
A 2 001d 0020 .byte 32,1+ 'A'
001e 0042
A 3 .copy "word.asm"
B 1 ** In word.asm
B 2 0020 ABCD .word 0ABCDh, 56q
0022 002E
A 4 ** Back in byte.asm
A 5 0024 006A .byte 67h + 3q
3
4 ** Back in original file
5 0025 0064 .string "done"
0026 006F
0027 006E
0028 0065
In this example, the .include directive is used to read and assemble source statements from other files; then, the assembler resumes assembling into the current file. The mechanism is similar to the .copy directive, except that statements are not printed in the listing file.
include.asm (source file) |
byte2.asm (first copy file) |
word2.asm (second copy file) |
---|---|---|
|
|
|
Listing file:
1 0000 .space 29
2 .include "byte2.asm"
3
4 **Back in original file
5 0025 0064 .string "done"
0026 006F
0027 006E
0028 0065