Tms Assembler Directives
Tms Assembler Directives
-1
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections,
modifications, enhancements, improvements, and other changes to its products and services at
any time and to discontinue any product or service without notice. Customers should obtain the
latest relevant information before placing orders and should verify that such information is current
and complete. All products are sold subject to TI’s terms and conditions of sale supplied at the
time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of
sale in accordance with TI’s standard warranty. Testing and other quality control techniques are
used to the extent TI deems necessary to support this warranty. Except where mandated by
government requirements, testing of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are
responsible for their products and applications using TI components. To minimize the risks
associated with customer products and applications, customers should provide adequate design
and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any
TI patent right, copyright, mask work right, or other TI intellectual property right relating to any
combination, machine, or process in which TI products or services are used. Information
published by TI regarding third party products or services does not constitute a license from TI
to use such products or services or a warranty or endorsement thereof. Use of such information
may require a license from a third party under the patents or other intellectual property of that third
party, or a license from TI under the patents or other intellectual property of TI.
Resale of TI products or services with statements different from or beyond the parameters stated
by TI for that product or service voids all express and any implied warranties for the associated
TI product or service and is an unfair and deceptive business practice. TI is not responsible or
liable for any such statements.
Mailing Address:
Texas Instruments
Post Office Box 655303
Dallas, Texas 75265
Notational Conventions
abs500 filename
abs500 is a command. The command invokes the absolute lister and has
one parameter, indicated by filename. When you invoke the absolute lis-
ter, you supply the name of the file that the absolute lister uses as input.
The hex500 command has two parameters. The first parameter, -options ,
is optional. Since options is plural, you may select several options. The
second parameter, filename, is required.
vi
Notational Conventions
The symbol is required for the .usect directive and must begin in column 1.
The section name must be enclosed in quotes and the section size in
words must be separated from the section name by a comma. The block-
ing flag and alignment flag are optional and, if used, must be separated by
commas.
This syntax shows that .byte must have at least one value parameter, but
you have the option of supplying additional value parameters, separated
by commas.
- Following are other symbols and abbreviations used throughout this docu-
ment.
The following books describe the TMS320C54x devices and related support
tools. To obtain a copy of any of these TI documents, call the Texas Instru-
ments Literature Response Center at (800) 477-8924. When ordering, please
identify the book by its title and literature number.
Trademarks
Code Composer Studio, TMS320C54x, and C54x are trademarks of Texas In-
struments Incorporated.
viii
Contents
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
Provides an overview of the software development tools.
1.1 Software Development Tools Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
1.2 Tools Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
ix
Contents
x
Contents
Contents xi
Contents
xii
Contents
6.10.5 Why the Dot Operator Does Not Always Work . . . . . . . . . . . . . . . . . . . . . . . . . . 6-52
6.10.6 Address and Dimension Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-53
6.11 Using UNION and GROUP Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-56
6.11.1 Overlaying Sections With the UNION Statement . . . . . . . . . . . . . . . . . . . . . . . . 6-56
6.11.2 Grouping Output Sections Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-58
6.11.3 Nesting UNIONs and GROUPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-59
6.11.4 Checking the Consistency of Allocators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-60
6.12 Overlay Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-61
6.12.1 Using the MEMORY Directive to Define Overlay Pages . . . . . . . . . . . . . . . . . . 6-61
6.12.2 Using Overlay Pages With the SECTIONS Directive . . . . . . . . . . . . . . . . . . . . 6-63
6.12.3 Page Definition Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-64
6.13 Default Allocation Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-66
6.13.1 Allocation Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-66
6.13.2 General Rules for Output Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-67
6.14 Special Section Types (DSECT, COPY, and NOLOAD) . . . . . . . . . . . . . . . . . . . . . . . . . 6-69
6.15 Assigning Symbols at Link Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-70
6.15.1 Syntax of Assignment Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-70
6.15.2 Assigning the SPC to a Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-71
6.15.3 Assignment Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-71
6.15.4 Symbols Defined by the Linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-73
6.15.5 Symbols Defined Only For C Support (-c or -cr Option) . . . . . . . . . . . . . . . . . 6-73
6.16 Creating and Filling Holes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-74
6.16.1 Initialized and Uninitialized Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-74
6.16.2 Creating Holes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-74
6.16.3 Filling Holes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-76
6.16.4 Explicit Initialization of Uninitialized Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-77
6.17 Partial (Incremental) Linking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-78
6.18 Linking C/C++ Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-80
6.18.1 Run-Time Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-80
6.18.2 Object Libraries and Run-Time Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-80
6.18.3 Setting the Size of the Stack and Heap Sections . . . . . . . . . . . . . . . . . . . . . . . . 6-81
6.18.4 Autoinitialization (ROM and RAM Models) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-81
6.18.5 The -c and -cr Linker Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-84
6.19 Linker Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-85
Contents xiii
Contents
xiv
Contents
10.9.5 Setting the Entry Point for the Boot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-32
10.9.6 Using the C54x Boot Loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-33
10.10 Controlling the ROM Device Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-35
10.10.1 Controlling the Starting Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-35
10.10.2 Controlling the Address Increment Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-37
10.10.3 The -byte Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-37
10.10.4 Dealing With Address Holes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-37
10.11 Description of the Object Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-39
10.11.1 ASCII-Hex Object Format (-a Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-40
10.11.2 Intel MCS-86 Object Format (-i Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-41
10.11.3 Motorola Exorciser Object Format (-m1, -m2, -m3 Options) . . . . . . . . . . . . 10-42
10.11.4 Texas Instruments SDSMAC Object Format (-t Option) . . . . . . . . . . . . . . . . . 10-43
10.11.5 Extended Tektronix Object Format (-x Option) . . . . . . . . . . . . . . . . . . . . . . . . 10-44
10.12 Hex Conversion Utility Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-45
Contents xv
Contents
F Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F-1
Defines terms and acronyms used in this book.
xvi
Figures
Figures
1-1 TMS320C54x Software Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
2-1 Partitioning Memory Into Logical Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
2-2 Object Code Generated by the File in Example 2-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
2-3 Combining Input Sections to Form an Executable Object Module . . . . . . . . . . . . . . . . . . . 2-14
3-1 Assembler Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
4-1 The .space and .bes Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15
4-2 The .field Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16
4-3 Initialization Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18
4-4 The .align Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20
4-5 Allocating .bss Blocks Within a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38
4-6 The .field Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-58
4-7 The .usect Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-109
6-1 Linker Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
6-2 Memory Map Defined in Example 6-3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-34
6-3 Section Allocation Defined by Example 6-4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-37
6-4 Run-Time Execution of Example 6-6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-51
6-5 Memory Allocation Shown in Example 6-8 and Example 6-9 . . . . . . . . . . . . . . . . . . . . . . 6-57
6-6 Overlay Pages Defined by Example 6-12 and Example 6-13 . . . . . . . . . . . . . . . . . . . . . . 6-62
6-7 RAM Model of Autoinitialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-82
6-8 ROM Model of Autoinitialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-83
7-1 Archiver Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
8-1 Absolute Lister Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
8-2 module1.lst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-9
8-3 module2.lst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-9
9-1 Cross-Reference Lister Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
10-1 Hex Conversion Utility Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
10-2 Hex Conversion Utility Process Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-9
10-3 Data and Memory Widths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-11
10-4 Data, Memory, and ROM Widths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13
10-5 C54x Memory Configuration Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-14
10-6 Varying the Word Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15
10-7 The infile.out File From Example 10-1 Partitioned Into Four Output Files . . . . . . . . . . . 10-20
10-8 Sample Command File for Booting From a C54x EPROM . . . . . . . . . . . . . . . . . . . . . . . . 10-34
10-9 Hex Command File for Avoiding a Hole at the Beginning of a Section . . . . . . . . . . . . . . 10-38
10-10 ASCII-Hex Object Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-40
10-1 1 Intel Hex Object Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-41
Contents xvii
Figures
xviii
Tables
Tables
3-1 Operators Used in Expressions (Precedence) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40
3-2 Expressions With Absolute and Relocatable Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-42
3-3 Assembler Built-In Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-44
3-4 Symbol Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-52
4-1 Assembler Directives Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
4-2 Memory-Mapped Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-82
5-1 Functions and Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
5-2 Creating Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-26
5-3 Manipulating Substitution Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-26
5-4 Conditional Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-26
5-5 Producing Assembly-Time Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27
5-6 Formatting the Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27
6-1 Linker Options Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
6-2 Linker Options Summary (Continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7
6-3 Operators Used in Expressions (Precedence) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-72
9-1 Symbol Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-6
10-1 Hex Conversion Utility Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4
10-2 Boot-Loader Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-29
10-3 Options for Specifying Hex Conversion Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-39
A-1 File Header Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-5
A-2 File Header Flags (Bytes 18 and 19) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-5
A-3 Optional File Header Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-6
A-4 Section Header Contents for COFF1 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-7
A-5 Section Header Contents for COFF2 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-8
A-6 Section Header Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-9
A-7 Relocation Entry Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-11
A-8 Relocation Types (Bytes 10 and 11) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-12
A-9 Line-Number Entry Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-13
A-10 Symbol Table Entry Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-16
A-1 1 Special Symbols in the Symbol Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-17
A-12 Symbol Storage Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-20
A-13 Special Symbols and Their Storage Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-21
A-14 Symbol Values and Storage Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-21
A-15 Section Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-22
A-16 Basic Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-23
A-17 Derived Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-23
Contents xix
Tables
xx
Examples
Examples
2-1 Using Sections Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
2-2 Code That Generates Relocation Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
3-1 C54x Data Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
3-2 C54x Code Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
3-3 $n Local Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
3-4 name? Local Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-38
3-5 Well-Defined Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-41
3-6 Assembler Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-49
3-7 Sample Cross-Reference Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-51
4-1 Sections Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13
5-1 Macro Definition, Call, and Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
5-2 Calling a Macro With Varying Numbers of Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7
5-3 The .asg Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
5-4 The .eval Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
5-5 Using Built-In Substitution Symbol Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
5-6 Recursive Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
5-7 Using the Forced Substitution Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
5-8 Using Subscripted Substitution Symbols to Redefine an Instruction . . . . . . . . . . . . . . . . . 5-12
5-9 Using Subscripted Substitution Symbols to Find Substrings . . . . . . . . . . . . . . . . . . . . . . . . 5-13
5-10 The .loop/.break/.endloop Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
5-1 1 Nested Conditional Assembly Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
5-12 Built-In Substitution Symbol Functions Used in a Conditional Assembly
Code Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
5-13 Unique Labels in a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
5-14 Producing Messages in a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21
5-15 Using Nested Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23
5-16 Using Recursive Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-24
6-1 Linker Command File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25
6-2 Command File With Linker Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26
6-3 The MEMORY Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-31
6-4 The SECTIONS Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-37
6-5 The Most Common Method of Specifying Section Contents . . . . . . . . . . . . . . . . . . . . . . . . 6-42
6-6 Copying a Section From ROM to RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-50
6-7 Using .label to Define a Load-Time Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-52
6-8 The UNION Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-56
6-9 Separate Load Addresses for UNION Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-56
Contents xxi
Examples
xxii
Notes
Notes
Default Section Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
asm500 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
Offsets in .struct and .union constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13
Differences in Precedence From Other TMS320 Assemblers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40
Labels and Comments in Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Use These Directives in Data Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
These Directives in a .struct/.endstruct Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17
Mixing Algebraic and Mnemonic Assembly Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33
Specifying an Alignment Flag Only . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-37
Directives That Can Appear in a .struct/.endstruct Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-99
Directives That Can Appear in a .union/.endunion Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-105
Specifying an Alignment Flag Only . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-107
- a and -r Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
Allocation of .stack and .sysstack Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18
Allocation of .stack and .sysstack Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18
Allocation of .stack and .sysstack Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-20
Use Byte Addresses in Linker Command File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-23
Use Byte Addresses in Linker Command File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24
Filenames and Option Parameters With Spaces or Hyphens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25
Filling Memory Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-33
Binding and Alignment or Named Memory are Incompatible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39
UNION and Overlay Page Are Not the Same . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-58
The PAGE Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-68
Allocation of .stack and .sysstack Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-73
Filling Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-77
Allocation of .stack and .sysstack Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-81
The TI-Tagged Format Is 16 Bits Wide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12
When the -order Option Applies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15
Sections Generated by the C/C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22
Using the -boot Option and the SECTIONS Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23
Defining the Ranges of Target Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-26
On-Chip Boot Loader Concerns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-32
Valid Entry Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-32
General Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-10
General Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-17
Contents xxiii
Chapter 1
Introduction
The assembly language tools create and use object files in common object file
format (COFF) to facilitate modular programming. Object files contain
separate blocks (called sections) of code and data that you can load into
C54xt memory spaces. You can program the C54x more efficiently if you
have a basic understanding of COFF. Chapter 2, Introduction to Common
Object File Format, discusses this object format in detail.
Topic Page
1-1
Software Development Tools Overview
C
source
files
Macro
source
files
C compiler
Assembly
Archiver translation
Assembler
assistant
source
Macro
library Assembler
source
Assembler
Library-build
COFF utility
object
Archiver
files
Runtime-
support
Library of library
object
files Linker
Debugging
tools
Executable
COFF
file
Hex conversion
utility
EPROM Cross-reference
programmer Absolute lister C54x
lister
1-2
Tools Descriptions
Introduction 1-3
Tools Descriptions
utility converts a COFF object file into TI-tagged, Intel, Motorola, or Tek-
tronix object format. The converted file can be downloaded to an EPROM
programmer.
- The absolute lister accepts linked object files as input and creates .abs
files as output. You assemble .abs files to produce a listing that contains
absolute rather than relative addresses. Without the absolute lister,
producing such a listing would be tedious and require many manual opera-
tions.
These debugging tools are accessed within Code Composer Studio. For more
information, see the Code Composer Studio User’s Guide.
1-4
Chapter 2
The assembler and linker create object files that can be executed by a
TMS320C54xt device. The format for these object files is called common
object file format (COFF).
Topic Page
2-1
COFF File Types
- COFF0
- COFF1
- COFF2
Each COFF file type has a different header format. The data portions of the
COFF files are identical. For details about the COFF file structure, see
Appendix A, Common Object File Format.
The TMS320C54x assembler and C compiler create COFF2 files. The linker
can read and write all types of COFF files. By default, the linker creates COFF2
files. Use the -v linker option to specify a different format. The linker supports
COFF0 and COFF1 files for older versions of the assembler and C compiler
only.
2-2
Sections
2.2 Sections
The smallest unit of an object file is called a section. A section is a block of code
or data that will ultimately occupy contiguous space in the memory map. Each
section of an object file is separate and distinct. COFF object files always con-
tain three default sections:
In addition, the assembler and linker allow you to create, name, and link named
sections that are used like the .data, .text, and .bss sections.
initialized sections contain data or code. The .text and .data sections
are initialized; named sections created with the
.sect assembler directive are also initialized.
uninitialized sections reserve space for uninitialized data. The .bss sec-
tion is uninitialized; named sections created with
the .usect assembler directive are also uninitial-
ized.
One of the linker’s functions is to relocate sections into the target memory map;
this function is called allocation. Because most systems contain several types
of memory, using sections can help you use target memory more efficiently.
All sections are independently relocatable; you can place any section into any
allocated block of target memory. For example, you can define a section that
contains an initialization routine and then allocate the routine into a portion of
the memory map that contains ROM.
Figure 2-1 shows the relationship between sections in an object file and a
hypothetical target memory.
.bss RAM
.data EEPROM
.text
ROM
2-4
How the Assembler Handles Sections
- .bss
- .usect
- .text
- .data
- .sect
The .bss and .usect directives create uninitialized sections; the other
directives create initialized sections.
You can create subsections of any section to give you tighter control of the
memory map. Subsections are created using the .sect and .usect directives.
Subsections are identified with the base section name and a subsection name
separated by a colon. See section 2.3.4, Subsections, page 2-9, for more
information.
Uninitialized data areas are built by using the .bss and .usect assembler
directives.
Each time you invoke the .bss directive, the assembler reserves more space
in the appropriate section. Each time you invoke the .usect directive, the
assembler reserves more space in the specified named section.
symbol points to the first word reserved by this invocation of the .bss
or .usect directive. The symbol corresponds to the name of
the variable that you’re reserving space for. It can be refer-
enced by any other section and can also be declared as a
global symbol (with the .global assembler directive).
size in words is an absolute expression.
- The .bss directive reserves size words in the .bss sec-
tion.
- The .usect directive reserves size words in section
name.
blocking flag is an optional parameter. If you specify a value other than
0 for this parameter, the assembler associates size words
contiguously; the allocated space will not cross a page
boundary, unless size is greater than a page, in which case
the object will start on a page boundary.
alignment flag is an optional parameter.
section name tells the assembler which named section to reserve space
in. For more information about named sections, see
subsection 2.3.3, Named Sections, on page 2-8.
The .text, .data, and .sect directives tell the assembler to stop assembling into
the current section and begin assembling into the indicated section. The .bss
and .usect directives, however, do not end the current section and begin a new
one; they simply escape temporarily from the current section. The .bss and
.usect directives can appear anywhere in an initialized section without
affecting its contents.
Uninitialized subsections can be created with the .usect directive. The assem-
bler treats uninitialized subsections in the same manner as uninitialized
sections. See subsection 2.3.4, Subsections, on page 2-9 for more informa-
tion on creating subsections.
2-6
How the Assembler Handles Sections
Three directives tell the assembler to place code or data into a section. The
syntaxes for these directives are:
.text [value]
.data [value]
.sect ”section name” [, value]
Sections are built through an iterative process. For example, when the assem-
bler first encounters a .data directive, the .data section is empty. The state-
ments following this first .data directive are assembled into the .data section
(until the assembler encounters a .text or .sect directive). If the assembler
encounters subsequent .data directives, it adds the statements following
these .data directives to the statements already in the .data section. This
creates a single .data section that can be allocated contiguously into memory.
Initialized subsections can be created with the .sect directive. The assembler
treats initialized subsections in the same manner as initialized sections. See
subsection 2.3.4, Subsections, on page 2-9 for more information on creating
subsections.
For example, repeated use of the .text directive builds up a single .text section
in the object file. When linked, this .text section is allocated into memory as a
single unit. Suppose there is a portion of executable code (perhaps an initiali-
zation routine) that you don’t want allocated with .text. If you assemble this
segment of code into a named section, it is assembled separately from .text,
and you can allocate it into memory separately. You can also assemble initial-
ized data that is separate from the .data section, and you can reserve space
for uninitialized variables that is separate from the .bss section.
- The .usect directive creates sections that are used like the .bss section.
These sections reserve space in RAM for variables.
- The .sect directive creates sections, like the default .text and .data
sections, that can contain code or data. The .sect directive creates named
sections with relocatable addresses.
The section name parameter is the name of the section. You can create up to
32 767 separate named sections. A section name can be up to 200 characters.
For the .sect and .usect directives, a section name can refer to a subsection
(see subsection 2.3.4, Subsections, for details).
Each time you invoke one of these directives with a new name, you create a
new named section. Each time you invoke one of these directives with a name
that was already used, the assembler assembles code or data (or reserves
space) into the section with that name. You cannot use the same names with
different directives. That is, you cannot create a section with the .usect direc-
tive and then try to use the same section with .sect.
2-8
How the Assembler Handles Sections
2.3.4 Subsections
Subsections are smaller sections within larger sections. Like sections,
subsections can be manipulated by the linker. Subsections give you tighter
control of the memory map. You can create subsections by using the .sect or
.usect directive. The syntax for a subsection name is:
Subsections are allocated in the same manner as sections. See Section 6.9,
The SECTIONS Directive, on page 6-35 for more information.
The format in Example 2-1 is a listing file. Example 2-1 shows how the SPCs
are modified during assembly. A line in a listing file has four fields:
2-10
How the Assembler Handles Sections
2 ************************************************
3 ** Assemble an initialized table into .data. **
4 ************************************************
5 000000 .data
6 000000 0011 coeff .word 011h,022h,033h
000001 0022
000002 0033
7 ************************************************
8 ** Reserve space in .bss for a variable. **
9 ************************************************
10 000000 .bss buffer,10
11 ************************************************
12 ** Still in .data. **
13 ************************************************
14 000003 0123 ptr .word 0123h
15 ************************************************
16 ** Assemble code into the .text section. **
17 ************************************************
18 000000 .text
19 000000 100f add: LD 0Fh,A
20 000001 f010 aloop: SUB #1,A
000002 0001
21 000003 f842 BC aloop,AGEQ
000004 0001’
22 ************************************************
23 ** Another initialized table into .data. **
24 ************************************************
25 000004 .data
26 000004 00aa ivals .word 0AAh, 0BBh, 0CCh
000005 00bb
000006 00cc
27 ************************************************
28 ** Define another section for more variables. **
29 ************************************************
30 000000 var2 .usect ”newvars”, 1
31 000001 inbuf .usect ”newvars”, 7
32 ************************************************
33 ** Assemble more code into .text. **
34 ************************************************
35 000005 .text
36 000005 110a mpy: LD 0Ah,B
37 000006 f166 mloop: MPY #0Ah,B
000007 000a
38 000008 f868 BC mloop,BNOV
000009 0006’
39 ************************************************
40 ** Define a named section for int. vectors. **
41 ************************************************
42 000000 .sect ”vectors”
43 000000 0011 .word 011h, 033h
44 000001 0033
As Figure 2-2 shows, the file in Example 2-1 creates five sections:
The second column shows the object code that is assembled into these
sections; the first column shows the line numbers of the source statements that
generated the object code.
6 0011 .data
6 0022
6 0033
14 0123
26 00aa
26 00bb
26 00cc
43 0011 vectors
44 0033
No data— .bss
10 10 words
reserved
No data— newvars
30 eight words
31 reserved
2-12
How the Linker Handles Sections
- The MEMORY directive allows you to define the memory map of a target
system. You can name portions of memory and specify their starting
addresses and their lengths.
- The SECTIONS directive tells the linker how to combine input sections
into output sections and where to place these output sections in memory.
Subsections allow you to manipulate sections with greater precision. You can
specify subsections with the linker’s SECTIONS directive. If you do not specify
a subsection explicitly, then the subsection is combined with the other sections
with the same base section name.
It is not always necessary to use linker directives. If you don’t use them, the
linker uses the target processor’s default allocation algorithm described in
Section 6.13, Default Allocation Algorithm, on page 6-66. When you do use
linker directives, you must specify them in a linker command file.
Refer to the following sections for more information about linker command files
and linker directives:
.text
.bss Executable
object module Memory map
.data file1
(.text) Executable
code
Init file2 (.text)
(named section) (.text)
file1
(.data) Initialized
data
file2 (.data)
(.data)
file1
(.bss) Space for
file2.obj
variables
file2 (.bss)
.text (.bss)
Tables
(named section)
In Figure 2-3, file1.obj and file2.obj have been assembled to be used as linker
input. Each contains the .text, .data, and .bss default sections; in addition,
each contains named sections. The executable output module shows the
combined sections. The linker combines file1.text with file2.text to form one
.text section, then combines the .data sections, then the .bss sections, and
finally places the named sections at the end. The memory map shows how the
sections are put into memory; by default, the linker begins at address 080h and
places the sections one after the other as shown.
2-14
How the Linker Handles Sections
For further explanation of section placement within the memory map, see
Section 6.8, The MEMORY Directive, on page 6-30 and Section 6.9, The
SECTIONS Directive, on page 6-35.
2.5 Relocation
The assembler treats each section as if it began at address 0. All relocatable
symbols (labels) are relative to address 0 in their sections. Of course, all
sections can’t actually begin at address 0 in memory, so the linker relocates
sections by:
- Allocating them into the memory map so that they begin at the appropriate
address
The linker uses relocation entries to adjust references to symbol values. The
assembler creates a relocation entry each time a relocatable symbol is refer-
enced. The linker then uses these entries to patch the references after the
symbols are relocated. Example 2-2 contains a code segment for the C54x
that generates relocation entries.
1 .ref X
2 .ref Z
3 000000 .text
4 000000 F073 B Y ; Generates a Relocation
Entry
000001 0006’
5 000002 F073 B Z ; Generates a Relocation
Entry
000003 0000!
6 000004 F020 LD #X, A ; Generates a Relocation
Entry
000005 0000!
5 000006 F7E0 Y: RESET
2-16
Relocation
1 .ref X
2 .ref Z
3 000000 .text
4 000000 F073 goto Y ; Generates a Relocation
Entry
000001 0006’
5 000002 F073 B Z ; Generates a Relocation
Entry
000003 0000!
6 000004 F020 A = #X ; Generates a Relocation
Entry
000005 0000!
7 000006 F7E0 Y: reset
2-18
Relocation
The linker provides a simple way to handle this. Using the SECTIONS
directive, you can optionally direct the linker to allocate a section twice: first to
set its load address, and again to set its run address. Use the load keyword
for the load address and the run keyword for the run address.
The load address determines where a loader will place the raw data for the
section. Any references to the section (such as labels in it) refer to its run
address. The application must copy the section from its load address to its run
address; this does not happen automatically simply because you specify a
separate run address. For an example that illustrates how to move a block of
code at runtime, see Example 6-6 on page 6-50.
If you provide only one allocation (either load or run) for a section, the section
is allocated only once and will load and run at the same address. If you provide
both allocations, the section is actually allocated as if it were two different
sections of the same size.
Uninitialized sections (such as .bss) are not loaded, so the only significant
address is the run address. The linker allocates uninitialized sections only
once: if you specify both run and load addresses, the linker warns you and
ignores the load address.
2-20
Loading a Program
Several methods can be used for loading a program, depending on the execu-
tion environment. Two common situations are described below.
- You can use the hex conversion utility (hex500, which is shipped as part
of the assembly language package) to convert the executable COFF
object module into one of several object file formats. You can then use the
converted file with an EPROM programmer to burn the program into an
EPROM.
The .def definition of x says that it is an external symbol defined in this module
and that other modules can reference x. The .ref definition of y says that it is
an undefined symbol that is defined in another module.
The assembler places both x and y in the object file’s symbol table. When the
file is linked with other object files, the entry for x defines unresolved
references to x from other files. The entry for y causes the linker to look through
the symbol tables of other files for y’s definition.
The linker must match all references with corresponding definitions. If the
linker cannot find a symbol’s definition, it prints an error message about the
unresolved reference. This type of error prevents the linker from creating an
executable object module.
2-22
Symbols in a COFF File
The assembler does not usually create symbol table entries for any symbols
other than those described above, because the linker does not use them. For
example, labels are not included in the symbol table unless they are declared
with .global. For symbolic debugging purposes, it is sometimes useful to have
entries in the symbol table for each symbol in a program. To accomplish this,
invoke the assembler with the -s option.
Assembler Description
Topic Page
3.1 Assembler Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
3.2 Assembler Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
3.3 Invoking the Assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
3.4 C54x Assembler Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13
3.5 Naming Alternate Files and Directories for Assembler Input . . . . . 3-21
3.6 Source Statement Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
3.7 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
3.8 Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31
3.9 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
3.10 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-39
3.11 Built-In Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-44
3.12 Loading Values into Extended Program Memory . . . . . . . . . . . . . . . . 3-46
3.13 Source Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47
3.14 Cross-Reference Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-51
3-1
Assembler Overview
- Produces a source listing (if requested) and provides you with control over
this listing
- Allows you to segment your code into sections and maintain an SPC
(section program counter) for each section of object code
The cl500 assembler generates error and warning messages for C54x
instructions that are not supported. Some C54x instructions do not map
directly to a single C54x instruction. The cl500 assembler will translate these
instructions into an appropriate series of C54x instructions. The listing file gen-
erated by the assembler (with the -l option) shows the translations that have
occurred.
3-2
Assembler Development Flow
C
source
files
Macro
source
files
C compiler
Translator
Archiver utility
Assembler
source
Macro
library Assembler
source
Assembler
Library-build
COFF utility
object
Archiver
files
Runtime-
support
Library of library
object
files Linker
Debugging
tools
Executable
COFF
file
Hex conversion
utility
EPROM Cross-reference
Absolute lister
programmer lister C54x
cl500 is the command that invokes the assembler. cl500 considers any
file with the extension .asm to be an assembly file and will call the
assembler.
input file names the assembly language source file. If you do not supply
an extension, the assembler uses the default extension .asm,
unless the -f assembler option is used. If you do not supply an
input filename, the assembler prompts you for one.
The source file can contain mnemonic or algebraic instructions,
but not both. The default instruction set is mnemonic. To specify
the algebraic instruction set, use the -mg option.
input file names the assembly language source file. If you do not supply
an extension, the assembler uses the default extension .asm,
unless the -f assembler option is used. If you do not supply an
input filename, the assembler prompts you for one.
The source file can contain mnemonic or algebraic instructions,
but not both. The default instruction set is mnemonic. To specify
the algebraic instruction set, use the -mg option.
object file names the C54x object file that the assembler creates. If you do
not supply an extension, the assembler uses .obj as a default. If
you do not supply an object file, the assembler creates a file that
uses the input filename with the .obj extension.
listing file names the optional listing file that the assembler can create.
- If you do not supply a listing file, the assembler does not
create one unless you use the -l (lowercase L) option or the
-x option. In this case, the assembler uses the input filename
with a .lst extension and places the listing file in the input file
directory.
- If you supply a listing file but do not supply an extension, the
assembler uses .lst as the default extension.
options identifies the assembler options that you want to use. Options
are not case-sensitive and can appear anywhere on the com-
mand line, following the assembler name. Precede each option
with a hyphen. Single-letter options without parameters can be
combined: for example, -lc is equivalent to -l -c. Options that
have parameters, such as -i, must be specified separately.
3-4
Invoking the Assembler
3-6
Invoking the Assembler
Note: asm500
To allow for future enhancement of the Code Generation Tools, direct invoca-
tion of the assembler (asm500) is deprecated. However, you can directly in-
voke the assembler if desired.
3-8
Invoking the Assembler
listing file names the optional listing file that the assembler can create.
- If you do not supply a listing file, the assembler does not
create one unless you use the -l (lowercase L) option or the
-x option. In this case, the assembler uses the input filename
with a .lst extension and places the listing file in the input file
directory.
- If you supply a listing file but do not supply an extension, the
assembler uses .lst as the default extension.
options identifies the assembler options that you want to use. Options
are not case-sensitive and can appear anywhere on the com-
mand line, following the assembler name. Precede each option
with a hyphen. Single-letter options without parameters can be
combined: for example, -lc is equivalent to -l -c. Options that
have parameters, such as -i, must be specified separately.
-@ -@ filename appends the contents of filename to
the command line. You can use this option to avoid
the limitations on command line length imposed by
the host operating system. Within a command file,
filenames or option parameters containing em-
bedded spaces or hyphens must be surrounded
with quotation marks.
For example: “this-file.asm”
-a creates an absolute listing. When you use -a, the
assembler does not produce an object file. The -a
option is used in conjunction with the absolute
lister.
-c makes case insignificant in the assembly
language files. For example, -c will make the sym-
bols ABC and abc equivalent. If you do not use this
option, case is significant (default). Case signifi-
cance is enforced primarily with symbol names,
not with mnemonics and register names.
-d -d name [=value] sets the name symbol. This is
equivalent to inserting name .set value at the
beginning of the assembly file. If value is omitted,
the symbol is set to 1. For more information, see
subsection 3.9.3, Defining Symbolic Constants
(-d Option), on page 3-33.
-f suppresses the assembler’s default behavior of
adding a .asm extension to a source file name that
does not already include an extension.
3-10
Invoking the Assembler
-mt informs the assembler that the SST status bit will
be disabled during the execution of this ported
C54x source file. By default, the assembler as-
sumes that the bit is enabled. (Supported for
asm500 only)
3-12
C54x Assembler Features
The assembler and the linker assume that your code is written using word
addresses and offsets in the context of data segments, and byte addresses
and offsets in the context of code segments:
- The PC-value column of the assembly listing file is counted in units that
are appropriate for the section being listed. For code sections, the PC is
counted in bytes; for data sections, it is counted in words.
For example:
1 000000 .text ; PC is counted in BYTES
2 000000 2298 MOV AR1,AR0
3 000002 4010 ADD #1,AC0
4
5 000000 .data ; PC is counted in WORDS
6 000000 0004 .word 4,5,6,7
000001 0005 ; PC is 1 word
000002 0006 ; PC is 2 words ...
000003 0007
7 000004 0001 foo .word 1
3-14
C54x Assembler Features
The code examples below display data and code for C54x.
.text
MOV *(#(Struct1 + 2)),T0 ; load 3rd WORD of Struct1
MOV *(#1000h),T1 ; 0x1000 is an absolute WORD
; address (i.e., byte 0x2000)
.text
.ref Func
CALL #(Func + 3) ;jump to address “Func plus 3 BYTES”
CALL #0x1000 ;0x1000 is an absolute BYTE address
The assembler does not support using a code address as if it were a data
address (e.g., attempting to read or write data to program space). Similarly, the
assembler does not support using a data address as if it were a code address
(e.g., executing a branch to a data label). This functionality cannot be
supported because of the difference in the size of the addressable units: a
code label address is a 24-bit byte address while a data label address is a
23-bit word address.
Consequently:
- You should not mix code and data within one section. All data (even
constant data) should be placed into a section separate from code.
- Applications that attempt to read and write bits into program sections will
not work.
The assembler may swap two instructions in order to make parallelism legal.
For example, both sets of instructions below are legal and will be encoded into
identical object bits:
AC0 = AC1 || T0 = T1 ^ #0x3333
T0 = T1 ^ #0x3333 || AC0 = AC1
In some cases, you may want the assembler to keep the largest (P24) form
of certain instructions. The P24 versions of certain instructions execute in
fewer cycles than the smaller version of the same instructions. For example,
“goto P24” uses 4 bytes and 3 cycles, while “goto L7” uses 2 bytes but 4 cycles.
Use the -mv assembler option or the .vli_off directive to keep the following
instructions in their largest form:
goto P24
call P24
3-16
C54x Assembler Features
The -mv assembler option suppresses the size resolution of the above
instructions within the entire file. The .vli_off and .vli_on directives can be used
to toggle this behavior for regions of an assembly file. In the case of a conflict
between the command line option and the directives, the directives take prece-
dence.
The scope of the .vli_off and .vli_on directives is static and not subject to the
control flow of the assembly program.
The memory modes correspond to the value of the C54CM, CPL, and ARMS
status bits. The assembler cannot track the value of the status bits. You must
use assembler directives and/or command line options to inform the
assembler of the value of these bits. An instruction that modifies the value of
the C54CM, CPL, or ARMS status bit must be immediately followed by an
appropriate assembler directive. When the assembler is aware of changes to
these bit values, it can provide useful error and warning messages about
syntax and semantic violations of these modes.
The scope of the .c54cm_on and .c54cm_off directives is static and not subject
to the control flow of the assembly program. All assembly code between the
.c54cm_on and .c54cm_off directives is assembled in C54x compatibility
mode.
CPL mode affects direct addressing. The assembler cannot track the value of
the CPL status bit. Consequently, you must use the .cpl_on and .cpl_off direc-
tives to model the CPL value. Issue one of these directives immediately follow-
ing any instruction that changes the value in the CPL bit. The .cpl_on directive
is similar to the CPL status bit set to 1; it is equivalent to using the -mc com-
mand line option. The .cpl_off directive is similar to the CPL status bit set to
0. The .cpl_on and .cpl_off directives take no arguments. In the case of a con-
flict between the command line option and the directive, the directive takes
precedence.
The scope of the .cpl_on, .cpl_off directives is static and not subject to the
control flow of the assembly program. All of the assembly code between the
.cpl_on line and the .cpl_off line is assembled in CPL mode.
The DP can be referenced in a file, but never defined in that file (it is set exter-
nally). Consequently, you must use the .dp directive to inform the assembler
of the DP value before it is used. Issue this directive immediately following any
instruction that changes the value in the DP register. The syntax of the directive
is:
.dp dp_value ; dp_value can be a constant or a symbolic
; expression
If the .dp directive is not used in a file, the assembler assumes that the value
of the DP is 0. The scope of the .dp directive is static and not subject to the
control flow of the program. The value set by the directive is used until the next
.dp directive is encountered, or until the end of the source file is reached.
Note that dma access to the MMR page and to the I/O page is processed iden-
tically by the assembler whether CPL mode is specified or not. Access to the
MMR page is indicated by the mmap() qualifier in the syntax. Access to the I/O
page is indicated by the readport() and writeport() qualifiers. These dma ac-
cesses are always encoded by the assembler as relative to the origin of 0.
3-18
C54x Assembler Features
In the case of a conflict between the command line option and the directive,
the directive takes precedence.
The scope of the .arms_on and .arms_off directives is static and not subject
to the control flow of the assembly program. All of the assembly code between
the .arms_on and the .arms_off directives is assembled in ARMS mode.
In ARMS mode (.arms_on), short offset modifiers for indirect memory access
are used. These modifiers are more efficient for code size optimization.
The best way to write this instruction, even though it is one byte longer, is:
ADD mmap(SP), T0
This warning will not be generated for C54x instructions inherited from C54x.
3-20
Naming Alternate Files and Directories for Assembler Input
.copy ”filename”
.include ”filename”
.mlib ”filename”
The filename names a copy/include file that the assembler reads statements
from or a macro library that contains macro definitions. The filename may be
a complete pathname, a partial pathname, or a filename with no path informa-
tion. The assembler searches for the file in the following order:
1) The directory that contains the current source file. The current source file
is the file being assembled when the .copy, .include, or .mlib directive is
encountered.
You can augment the assembler’s directory search algorithm by using the -i
assembler option or the C54X_A_DIR and A_DIR environment variables.
Each -i option names one pathname. There is no limit to the number of paths
that you can specify. In assembly source, you can use the .copy, .include, or
.mlib directive without specifying path information. If the assembler doesn’t
find the file in the directory that contains the current source file, it searches the
paths designated by the -i options.
For example, assume that a file called source.asm is in the current directory;
source.asm contains the following directive statement:
.copy ”copy.asm”
Assume that the file is stored in the following directory:
Windows c:\tools\files\copy.asm
UNIX /tools/files/copy.asm
The assembler first searches for copy.asm in the current directory because
source.asm is in the current directory. Then the assembler searches in the
directory named with the -i option.
The assembler looks for the C54X_A_DIR environment variable first and then
reads and processes it. If it does not find this variable, it reads the A_DIR envi-
ronment variable and processes it. If both variables are set, the settings of the
processor-specific variable are used. The processor-specific variable is useful
when you are using Texas Instruments tools for different processors at the
same time.
If the assembler doesn’t find C54X_A_DIR and/or A_DIR, it will then search
for C54X_C_DIR and C_DIR.
3-22
Naming Alternate Files and Directories for Assembler Input
assembly source, you can use the .copy, .include, or .mlib directive without
specifying path information. If the assembler doesn’t find the file in the direc-
tory that contains the current source file or in directories named by -i, it
searches the paths named by the environment variable.
For example, assume that a file called source.asm contains these statements:
.copy ”copy1.asm”
.copy ”copy2.asm”
Windows c:\tools\files\copy1.asm
c:\dsys\copy2.asm
UNIX /tools/files/copy1.asm
/dsys/copy2.asm
You could set up the search path with the commands shown in the following
table:
The assembler first searches for copy1.asm and copy2.asm in the current
directory because source.asm is in the current directory. Then the assembler
searches in the directory named with the -i option and finds copy1.asm.
Finally, the assembler searches the directory named with A_DIR and finds
copy2.asm.
Note that the environment variable remains set until you reboot the system or
reset the variable by entering one of these commands:
Algebraic syntax:
[label] [:] instruction [;comment]
- One or more blanks must separate each field. Tab characters are
equivalent to blanks.
- Comments are optional. Comments that begin in column 1 can begin with
an asterisk or a semicolon (* or ;), but comments that begin in any other
column must begin with a semicolon.
- A source line can be continued onto the next line by ending the first line
with a backslash (\) character.
3-24
Source Statement Format
When you use a label, its value is the current value of the section program
counter (the label points to the statement it’s associated with). If, for example,
you use the .word directive to initialize several words, a label would point to
the first word. In the following example, the label Start has the value 40h.
. . . .
. . . .
. . . .
9 000000 ; Assume some other code was assembled.
10 000040 000A Start: .word 0Ah,3,7
000041 0003
000042 0007
A label on a line by itself is a valid statement. The label assigns the current
value of the section program counter to the label; this is equivalent to the fol-
lowing directive statement:
label .set $ ; $ provides the current value of the SPC.
When a label appears on a line by itself, it is assigned to the address of the
instruction on the next line (the SPC is not incremented):
3 000043 Here:
4 000043 0003 .word 3
3-26
Source Statement Format
In the first statement, the immediate value mode is necessary to tell the
assembler to add the value 10 to accumulator A. In the second statement,
however, immediate value is not used; the assembler expects the operand
to be a value and initializes a byte with the value 10.
- Expressions that have more than one term that is used as a single operand
must be delimited with parentheses. This rule does not apply to state-
ments using a function call format, since they are already set off with
parentheses. For example, consider A = B & #(1 << sym) << 5. The
expression 1 << sym is used as a single operand and is therefore set off
with parentheses.
3.7 Constants
The assembler supports six types of constants:
- Binary integer
- Octal integer
- Decimal integer
- Hexadecimal integer
- Character
- Assembly time
- Floating-point
The assembler maintains each constant internally as a 32-bit quantity.
Constants are not sign-extended. For example, the constant 0FFH is equal to
00FF (base 16) or 255 (base 10); it does not equal -1.
In general, in C54x algebraic assembly source code, constants must begin
with a ’#’.
3.7.1 Binary Integers
A binary integer constant is a string of up to 16 binary digits (0s and 1s)
followed by the suffix B (or b). If fewer than 16 digits are specified, the
assembler right justifies the value and zero fills the unspecified bits. These are
examples of valid binary constants:
3-28
Constants
shift3 .set 3
MOV #shift3,AC0
You can also use the .set directive to assign symbolic constants for register
names. In this case, the symbol becomes a synonym for the register:
AuxR1 .set AR1
MVMM AuxR1, SP
Replace nnn with a string of decimal digits. You can precede nnn with a + or
a -. You must specify a decimal point. For example, 3.e5 is valid, but 3e5 is
not valid. The exponent indicates a power of 10. These are examples of valid
constants:
3.0
3.14
.3
-0.314e13
+314.59e-2
3-30
Character Strings
3.9 Symbols
Symbols are used as labels, constants, and substitution symbols. A symbol
name is a string of up to 200 alphanumeric characters (A- Z, a- z, 0- 9, $,
and _). The first character in a symbol cannot be a number, and symbols can-
not contain embedded blanks. The symbols you define are case sensitive; for
example, the assembler recognizes ABC, Abc, and abc as three unique
symbols. You can override case sensitivity with the -c assembler option. A
symbol is valid only during the assembly in which it is defined, unless you use
the .global directive to declare it as an external symbol.
3.9.1 Labels
Symbols used as labels become symbolic addresses associated with loca-
tions in the program. Labels used locally within a file must be unique.
Mnemonic opcodes and assembler directive names (without the ”.” prefix) are
valid label names.
Labels can also be used as the operands of .global, .ref, .def, or .bss directives;
for example:
.global label1
label2 NOP
ADD label1,B
B label2
3-32
Symbols
The assembler also has several predefined symbolic constants; these are
discussed in the next section.
asm500 -d name=[value]
The name is the name of the symbol you want to define. The value is the value
you want to assign to the symbol. If the value is omitted, the symbol is set to 1.
Within assembler source, you may test the symbol with the following direc-
tives:
Note that the argument to the $isdefed built-in function must be enclosed in
quotes. The quotes cause the argument to be interpreted literally rather than
as a substitution symbol.
- $, the dollar sign character, represents the current value of the section
program counter (SPC).
When you are using macros, substitution symbols are important because
macro parameters are actually substitution symbols that are assigned a macro
argument. The following code shows how substitution symbols are used in
macros:
3-34
Symbols
LD ADDRA, A
ADD ADDRB, A
STL A, ADDRB
.endm
; add2 invocation
add2 LOC1, LOC2 ;add ”LOC1” argument to a
;second argument ”LOC2”.
; instructions for expanded macro:
; LD LOC1, A
; ADD LOC2, A
; STL A, LOC2
Local labels are special labels whose scope and effect are temporary. A local
label can be defined in two ways:
- $n, where n is a decimal digit in the range of 0-9. For example, $4 and $1
are valid local labels.
- name?, where name is any legal symbol name as described above. The
assembler replaces the question mark with a period followed by a unique
number. When the source code is expanded, you will not see the unique
number in the listing file. Your label appears with the question mark as it
did in the macro definition. You cannot declare this label as global.
Normal labels must be unique (they can be declared only once), and they can
be used as constants in the operand field. Local labels, however, can be
undefined and defined again or automatically generated. Local labels cannot
be defined by directives.
Example 3-3 demonstrates the $n form of local labels. This example assumes
that symbols ADDRA, ADDRB, ADDRC have been defined previously.
3-36
Symbols
Local labels are especially useful in macros. If a macro contains a normal label
and is called more than once, the assembler issues a multiple-definition error.
If you use a local label and .newblock within a macro, however, the local label
is used and reset each time the macro is expanded.
Up to ten local labels of the $n form can be in effect at one time. Local labels
of the form name? are not limited. After you undefine a local label, you can de-
fine it and use it again. Local labels do not appear in the object code symbol
table.
The maximum label length is shortened to allow for the unique suffix. If the
macro is expanded fewer than 10 times, the maximum label length is 126 char-
acters. If the macro is expanded from 10 to 99 times, the maximum label length
is 125.
;*********************************************************
; First definition of local label ’mylab’
;*********************************************************
nop
mylab? nop
b mylab?
;*********************************************************
; Include file has second definition of ’mylab’
;*********************************************************
.copy ”a.inc”
;*********************************************************
;Third definition of ’mylab’, reset upon exit from include
;*********************************************************
mylab? nop
b mylab?
;*********************************************************
; Fourth definition of ’mylab’ in macro, macros use
; different namespace to avoid conflicts
;*********************************************************
mymac .macro
mylab? nop
b mylab?
.endm
;*********************************************************
; Macro invocation
;*********************************************************
mymac
;*********************************************************
; Reference to third definition of ’mylab’, note that
; definition is not reset by macro invocation nor
; conflicts with same name defined in macro
;*********************************************************
b mylab?;
*********************************************************
; Changing section, allowing fifth definition of ’mylab’
;*********************************************************
.sect ”Secto_One”
nop
mylab? .word 0
nop
nop
b mylab?
;*********************************************************
;.newblock directive, allowing sixth definition of ’mylab’
;*********************************************************
.newblock
mylab? .word 0
nop
nop
b mylab?
3-38
Expressions
3.10 Expressions
An expression is an operand or a series of operands separated by arithmetic
operators. An operand is an assembly-time constant or a link-time relocatable
symbol. The range of valid expression values is -32 768 to 32 767. Three
main factors influence the order of expression evaluation:
Precedence groups The C54x assembler uses the same order of prece-
dence as the C language does as summarized in
Table 3-1. This differs from the order of prece-
dence of other TMS320 assemblers. When paren-
theses do not determine the order of expression
evaluation, the highest precedence operation is
evaluated first.
8 + 4 / 2 = 10 (4 / 2 is evaluated first)
3.10.1 Operators
Table 3-1 lists the operators that can be used in expressions.
< <= > >= Less than, LT or equal, greater than, Left to right
GT or equal
Note: Unary +, -, and * have higher precedence than the binary forms.
3-40
Expressions
.data
label1 .word 0
.word 1
.word 2
label2 .word 3
X .set 50h
goodsym4 .set label2 - label1 ; Although label1 and label2 are not
; absolute symbols, because they are local
; labels defined in the same section, their
; difference can be computed by the assembler.
; The difference is absolute, so the
; expression is well-defined.
Symbols or registers that have been defined as global with the .global directive
can also be used in expressions; in Table 3-2, these symbols and registers are
referred to as external.
Following are examples of expressions that use relocatable and absolute sym-
bols. These examples use four symbols that are defined in the same section:
.global extern_1 ; Defined in an external module
intern_1: .word ’”D’ ; Relocatable, defined in current module
LAB1: .set 2 ; LAB1 = 2
intern_2 ; Relocatable, defined in current module
- Example 1
3-42
Expressions
- Example 2
- Example 3
The first statement below is legal; although intern_1 and intern_2 are
relocatable, their difference is absolute because they’re in the same
section. Subtracting one relocatable symbol from another reduces the
expression to relocatable symbol + absolute value. The second statement
is illegal because the sum of two relocatable symbols is not an absolute
value.
LD intern_1 - intern_2 + extern_1, B ; Legal
LD intern_1 + intern_2 + extern_1, B ; Illegal
- Example 4
The assembler supports built-in functions for conversions and various math
computations. Table 3-3 describes the built-in functions. Note that expr must
be a constant value. See Table 5-1 for a description of the assembler’s non-
mathematical built-in functions.
Function Description
$ceil(expr) returns the smallest integer that is not less than the
expression
$floor(expr) returns the largest integer that is not greater than the
expression
$fmod(expr1, expr2) returns the remainder after dividing expr1 and expr2
3-44
Built-in Functions
Function Description
Note that it is necessary to use both LDX and OR to load the entire 24-bit
address.
3-46
Source Listings
A source listing shows source statements and the object code they produce.
To obtain a listing file, invoke the assembler with the -l (lowercase L) option.
Two banner lines, a blank line, and a title line are at the top of each source list-
ing page. Any title supplied by a .title directive is printed on the title line; a page
number is printed to the right of the title. If you don’t use the .title directive, the
name of the source file is printed. The assembler inserts a blank line below the
title line.
Each line in the source file may produce a line in the listing file that shows a
source statement number, an SPC value, the object code assembled, and the
source statement. A source statement may produce more than one word of
object code. The assembler lists the SPC value and object code on a separate
line for each additional word. Each additional line is listed immediately
following the source statement line.
Line Number
The assembler may precede a line with a letter; the letter indicates
that the line is assembled from an included file.
The assembler may precede a line with a number; the number indi-
cates the nesting level of macro expansions or loop blocks.
This field contains the section program counter (SPC) value, which
is hexadecimal. All sections (.text, .data, .bss, and named sections)
maintain separate SPCs. Some directives do not affect the SPC and
leave this field blank.
Example 3-6 shows an assembler listing with each of the four fields identified.
3-48
Source Listings
3-50
Cross-Reference Listings
INT0 0002+ 14 2
INT1 0004+ 15 2
INT2 0006+ 16 2
ISR0 REF 4 14
ISR1 REF 4 15
ISR2 REF 4 16
RESET 0000+ 13 2
RINT 0002+ 24 3
TINT 0000+ 23 3
VECS 0006+ 26 3
XINT 0004+ 27
init 0000+ 34 13
.global ABC
nop
nop
(b) incl1.asm
.global ABC
ld ABC, A
(c) incl2.asm
.global ABC
stl A,ABC
(d) xref.asm
start:
.include “incl0.asm”
.include “incl1.asm”
add #10,A
.include “incl2.asm”
nop
nop
b start
.global start
.bss ABC,2
3-52
Cross-Reference Listings
Assembler Directives
Assembler directives supply data to the program and control the assembly
process. Assembler directives enable you to do the following:
This chapter is divided into two parts: the first part (Sections 4.1 through 4.10)
describes the directives according to function, and the second part
(Section 4.11) is an alphabetical reference.
Topic Page
4.1 Directives Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
4.2 Compatibility With the TMS320C1x/C2x/C2xx/C5x Assembler
Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10
4.3 Directives That Define Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11
4.4 Directives That Initialize Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
4.5 Directives That Align the Section Program Counter . . . . . . . . . . . . . 4-19
4.6 Directives That Format the Output Listing . . . . . . . . . . . . . . . . . . . . . . 4-21
4.7 Directives That Reference Other Files . . . . . . . . . . . . . . . . . . . . . . . . . 4-23
4.8 Conditional Assembly Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24
4.9 Assembly-Time Symbol Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25
4.10 Miscellaneous Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27
4.11 Directives Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30
4-1
Directives Summary
- The assembler uses several directives for macros. The macro directives
are listed in this chapter, but they are described in detail in Chapter 5,
Macro Language.
- The absolute lister also uses directives. Absolute listing directives are not
entered by the user but are inserted into the source program by the
absolute lister. Chapter 8, Absolute Lister Description, discusses these
directives; they are not discussed in this chapter.
- The C/C++ compiler uses directives for symbolic debugging. Unlike other
directives, symbolic debugging directives are not used in most assembly
language programs. Appendix B, Symbolic Debugging Directives,
discusses these directives; they are not discussed in this chapter.
4-2
Directives Summary
.pstring ”string1 ” [, ... ,”stringn ”] Initialize one or more text strings (packed). 4-97
.space size in bits; Reserve size bits in the current section; note that a --
label points to the beginning of the reserved space
.string ”string1 ” [, ... , ”stringn ”] Initialize one or more text strings 4-97
4-4
Directives Summary
4-6
Directives Summary
.warn_off Identify the beginning of a block of code for which the 4-111
assembler’s warning messages will be suppressed.
.version [value] Specify the device for which processor instructions 4-112
are being built
.wmsg string Send user-defined warning messages to the output 4-51
device
4-8
Directives Summary
- The C54x .long and .float directives place the most significant word of the
value at the lower address, while the C1x/C2x/C2xx/C5x assembler direc-
tives place the least significant word at the lower address. Also, the C54x
.long and .float directives automatically align the SPC on an even word
boundary, while the C1x/C2x/C2xx/C5x assembler directives do not.
- The .field directive for the C54x packs fields into words starting at the most
significant bit of the word. The C1x/C2x/C2xx/C5x assembler .field direc-
tive places fields into words starting at the least significant bit of the word.
- The .field directive for the C54x handles values of 1 to 32 bits, contrasted
with the C1x/C2x/C2xx/C5x assembler which handles values of 1 to 16
bits. With the C54x assembler, objects that are 16 bits or larger start on
a word boundary and are placed with the most significant bits at the lower
address.
- The C54x .bss and .usect directives have an additional flag called the
alignment flag which specifies alignment on an even word boundary. The
C1x/C2x/C2xx/C5x .bss and .usect directives do not use this flag.
- The .string directive for the C54x initializes one character per word, unlike
the C1x/C2x/C2xx/C5x assembler .string, which packs two characters per
word. The new .pstring directive packs two characters per word, as the for-
mer .string did.
- The following directives are new with the C54x assembler and are not sup-
ported by the C1x/C2x/C2xx/C5x assembler:
Directive Usage
.xfloat Same as .float without automatic alignment
4-10
Directives That Define Sections
- .clink sets the STYP_CLINK flag in the type field for the named section.
The .clink directive can be applied to initialized or uninitialized sections.
The STYP_CLINK flag enables conditional linking by telling the linker to
leave the section out of the final COFF output of the linker if there are no
references found to any symbol in the section.
- .data identifies portions of code in the .data section. The .data section
usually contains initialized data.
- .sect defines initialized named sections and associates subsequent code
or data with that section. A section defined with .sect can contain execut-
able code or data.
- .csect defines an initialized, named code section that may contain
directives that define data. Normally, the assembler will not accept a
section containing both code and data. However, there are some situa-
tions in which data must be defined within a code section. Such a code
section should be created with .csect.
- .text identifies portions of code in the .text section. The .text section
usually contains executable code.
- .usect reserves space in an uninitialized named section. The .usect
directive is similar to the .bss directive, but it allows you to reserve space
separately from the .bss section.
Example 4-1 shows how you can use sections directives to associate code
and data with the proper sections. This is an output listing; column 1 shows line
numbers, and column 2 shows the SPC values. (Each section has its own pro-
gram counter, or SPC.) When code is first placed in a section, its SPC equals
0. When you resume assembling into a section after other code is assembled,
the section’s SPC resumes counting as if there had been no intervening code.
The directives in Example 4-1 perform the following tasks:
The .bss and .usect directives do not end the current section or begin new
sections; they reserve the specified amount of space, and then the assembler
resumes assembling code or data into the current section.
4-12
Directives That Define Sections
- The .bes and .space directives reserve a specified number of bits in the
current section. The assembler fills these reserved bits with 0s.
4-14
Directives That Initialize Constants
Res_1 = 02h
17 bits
reserved
20 bits
reserved Res_2 = 06h
- The .byte, .ubyte, .char, and .uchar directives place one or more 8-bit
values into consecutive words of the current section. These directives are
similar to .word and .uword, except that the width of each value is
restricted to 8 bits.
- The .field directive places a single value into a specified number of bits
in the current word. With .field, you can pack multiple fields into a single
word; the assembler does not increment the SPC until a word is filled.
Figure 4-2 shows how fields are packed into a word. For this example,
assume the following code has been assembled; notice that the SPC
doesn’t change for the first three fields (the fields are packed into the same
word):
4 000000 6000 .field 3, 3
5 000000 6400 .field 8, 6
6 000000 6440 .field 16, 5
7 000001 0123 .field 01234h,20
000002 4000
8 000003 0000 .field 01234h,32
000004 1234
3 bits
15 12 11 10 9 8 7 0
.field 8,6
0 1 1 0 0 1 0 0 0
6 bits
15 6 5 4 3 2 0
0 1 1 0 0 1 0 0 0 1 0 0 0 0 0 0 .field 16,5
5 bits
15
0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 .field 01234h,20
15
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .field 01234h,32
15
0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0
4-16
Directives That Initialize Constants
secutive words in the current section. The most significant word is stored
first. The .float directive automatically aligns to the nearest long word
boundary, and .xfloat does not.
- .int, .uint, .half, .uhalf, .short, .ushort, .word, and .uword place one or
more 16-bit values into consecutive words in the current section.
- .long, .ulong, and .xlong place 32-bit values into two consecutive words
in the current section. The most significant word is stored first. The .long
directive automatically aligns to a long word boundary, and the .xlong
directive does not.
- .string and .pstring place 8-bit characters from one or more character
strings into the current section. The .string directive is similar to .byte, plac-
ing an 8-bit character in each consecutive word of the current section. The
.pstring also has a width of 8 bits but packs two characters into a word. For
.pstring, the last word in a string is padded with null characters (0) if
necessary.
Figure 4-3 compares the .byte, .int, .long, .xlong, .float, .xfloat, .word, and
.string directives. For this example, assume that the following code has been
assembled:
1 000000 00aa .byte 0AAh, 0BBh
000001 00bb
2 000002 0ccc .word 0CCCh
3 000003 0eee .xlong 0EEEEFFFh
000004 efff
4 000006 eeee .long 0EEEEFFFFh
000007 ffff
5 000008 dddd .int 0DDDDh
6 000009 3fff .xfloat 1.99999
00000a ffac
7 00000c 3fff .float 1.99999
00000d ffac
8 00000e 0068 .string ”help”
00000f 0065
000010 006c
000011 0070
2, 3 0 C C C .word OCCCh
c, d D D D D .int DDDDh
4-18
Directives That Align the Section Program Counter
The .even directive aligns the SPC so that it points to the next word boundary.
It is equivalent to specifying the .align directive with an operand of 1. Using
.even with an operand of 2 aligns the SPC to the next long word boundary. Any
unused bits in the current word are filled with 0s.
Figure 4-4 demonstrates the .align directive. Assume that the following code
has been assembled:
1 000000 4000 .field 2, 3
2 000000 4160 .field 11, 8
3 .align 2
4 000002 0045 .string ”Errorcnt”
000003 0072
000004 0072
000005 006f
000006 0072
000007 0063
000008 006e
000009 0074
5 .align
6 000080 0004 .byte 4
00h
128
(a) Current words (b) New SPC =
SPC 80h after
assembling
80h a .align
directive
4-20
Directives That Format the Output Listing
- The listing file contains a listing of false conditional blocks that do not gen-
erate code. The .fclist and .fcnolist directives turn this listing on and off.
You can use the .fclist directive to list false conditional blocks exactly as
they appear in the source code. This is the default behavior of the
assembler. You can use the .fcnolist directive to list only the conditional
blocks that are actually assembled.
- The .length directive controls the page length of the listing file. You can
use this directive to adjust listings for various output devices.
- The .list and .nolist directives turn the output listing on and off. You can
use the .nolist directive to stop the assembler from printing selected
source statements in the listing file. Use the .list directive to turn the listing
on again.
- The listing file contains a listing of macro expansions and loop blocks. The
.mlist and .mnolist directives turn this listing on and off. You can use the
.mlist directive to print all macro expansions and loop blocks to the listing
(the default behavior of the assembler), and the .mnolist directive to
suppress this listing.
- The .option directive controls certain features in the listing file. This
directive has the following operands:
- The .title directive supplies a title that the assembler prints at the top of
each page.
- The .width directive controls the page width of the listing file. You can use
this directive to adjust listings for various output devices.
4-22
Directives That Reference Other Files
- The .copy and .include directives tell the assembler to begin reading
source statements from another file. When the assembler finishes reading
the source statements in the copy/include file, it resumes reading source
statements from the current file immediately following the point at which
the .copy or .include directive occurred. The statements read from a
copied file are printed in the listing file; the statements read from an
included file are not printed in the listing file.
- The .def directive identifies a symbol that is defined in the current module
and that can be used by another module. The assembler includes the
symbol in the symbol table.
- The .ref directive identifies a symbol that is used in the current module but
defined in another module. The assembler marks the symbol as an
undefined external symbol and enters it in the object symbol table so that
the linker can resolve its definition.
The assembler supports several relational operators that are useful for
conditional expressions. For more information about relational operators, see
subsection 3.10.4, Conditional Expressions, on page 3-41.
4-24
Assembly-Time Symbol Directives
.byte coefficients
- The .label directive defines a special symbol that refers to the loadtime
address within the current section. This is useful when a section loads at
one address but runs at a different address. For example, you may want
to load a block of performance-critical code into slower off-chip memory
to save space, and move the code to high-speed on-chip memory to run.
- The .set and .equ directives set a value to a symbol. The symbol is stored
in the symbol table and cannot be refined. For example:
bval .set 0100h
.byte bval, bval*2, bval+12
B bval
The .set and .equ directives produce no object code. The two directives
are identical and can be used interchangeably.
4-26
Miscellaneous Directives
- The .algebraic directive tells the assembler that the file contains algebraic
assembly source code. This must be the first line in the file if the -mg
assembler option is not used.
- The .c_mode directive tells the assembler that calls and branches are
within the normal 16-bit address range. This is the default behavior of the
assembler.
- The .dp directive specifies the value of the DP register. The assembler
cannot track the value of the DP register; however, it needs to know the
value of DP in order to assemble direct memory access operands. Conse-
quently, this directive should be placed immediately following any instruc-
tion that changes the DP register’s value. If the assembler is not given any
information on the value of the DP register, it assumes the value is 0 when
encoding direct memory operands.
- The .ivec directive is used to initialize the entries in the interrupt vector
table.
- The .localalign directive allows the maximum localrepeat loop size for the
specified loop.
- The .far_mode directive tells the assembler that calls are far calls.
- The .newblock directive resets local labels. Local labels are symbols of
the form $n or name?. They are defined when they appear in the label field.
Local labels are temporary labels that can be used as operands for jump
instructions. The .newblock directive limits the scope of local labels by
resetting them after they are used. For more information about local
labels, see subsection 3.9.6, Local Labels, on page 3-36.
- The .vli_off directive begins a block of code in which the assembler will
use the largest (P24) forms of certain variable-length instructions. By de-
fault, the assembler tries to resolve variable-length instructions to their
smallest form. The .vli_on directive ends this block of code and resumes
the default behavior of the assembler.
- The .warn_off directive begins a block of code for which the assembler’s
warning messages are suppressed. By default, the assembler’s warning
messages are reported. The .warn_on directive ends this block of code
and resumes the default behavior of the assembler.
- The .version directive determines the processor for which instructions are
being built. Each C54x device has its own value.
These three directives enable you to define your own error and warning
messages:
- The .emsg directive sends error messages to the standard output device.
The .emsg directive generates errors in the same manner as the
assembler, incrementing the error count and preventing the assembler
from producing an object file.
- The .arms_on directive begins a block of code for which the assembler
will use indirect access modifiers targeted to code size optimization.
These modifiers are short offset modifiers. The .arms_off directive ends
the block of code.
4-28
Miscellaneous Directives
- The .cpl_on directive begins a block of code in which direct memory ad-
dressing (DMA) is relative to the stack pointer. By default, DMA is relative
to the data page. The .cpl_off directive ends the block of code.
- The .sst_off directive begins a block of code for which the assembler will
assume that the SST status bit is set to 0. By default, the assembler as-
sumes that the SST bit is set to 1. The .sst_on directive ends the block
of code.
4-30
Directives Reference
Syntax
.algebraic
Description The .algebraic directive tells the assembler that this file contains algebraic
assembly source code. This directive must be the first line in the file if the -mg
option is not used.
The .algebraic directive does not provide a method for mixing algebraic and
mnemonic statements within the same source file. It provides a means of
selecting algebraic assembly without specifying the -mg assembler option.
Syntax
.align [size]
.even
Description The .align directive aligns the section program counter (SPC) on the next
boundary, depending on the size parameter. The size may be any power of 2,
although only certain values are useful for alignment.
An operand of 128 aligns the SPC on the next page boundary, and this is the
default if no size is given. The assembler assembles words containing null
values (0) up to the next x-word boundary.
- The assembler sets a flag that forces the linker to align the section so that
individual alignments remain intact when a section is loaded into memory.
Example This example shows several types of alignment, including .even, .align 4, and
a default .align.
4-34
Assign Character Strings to Substitution Symbols .asg/.eval
Syntax
.asg [ ” ]character string[ ” ], substitution symbol
.eval well-defined expression, substitution symbol
Example This example shows how .asg and .eval can be used.
1 .sslist;show expanded sub. symbols
2 *
3 * .asg/.eval example
4 *
5 .asg *+, INC
6 .asg AR0, FP
7
8 000000 f000 ADD #100, A
000001 0064
9 000002 6d90 MAR *FP+
# MAR *AR0+
10
11
12 .asg 0, x
13 .loop 5
14 .eval x+1, x
15 .word x
16 .endloop
1 .eval x+1, x
# .eval 0+1, x
1 000003 0001 .word x
# .word 1
1 .eval x+1, x
# .eval 1+1, x
1 000004 0002 .word x
# .word 2
1 .eval x+1, x
# .eval 2+1, x
1 000005 0003 .word x
# .word 3
1 .eval x+1, x
# .eval 3+1, x
1 000006 0004 .word x
# .word 4
1 .eval x+1, x
# .eval 4+1, x
1 000007 0005 .word x
# .word 5
4-36
Reserve Space in the .bss Section .bss
Syntax
.bss symbol, size in words [, [blocking flag] [, alignment flag ] ]
Description The .bss directive reserves space for variables in the .bss section. This
directive is typically used to allocate variables in RAM.
- The symbol is a required parameter. It defines a label that points to the first
location reserved by the directive. The symbol name corresponds to the
variable that you’re reserving space for.
The assembler follows two rules when it allocates space in the .bss section:
Rule 1 Whenever a hole is left in memory (as shown in Figure 4-5), the
.bss directive attempts to fill it. When a .bss directive is assembled,
the assembler searches its list of holes left by previous .bss
directives and tries to allocate the current block into one of the
holes. (This is the standard procedure whether the contiguous al-
location option has been specified or not.)
Rule 2 If the assembler does not find a hole large enough to contain the
requested space, it checks to see whether the blocking option is re-
quested.
- If you do not request blocking, the memory is allocated at the
current SPC.
- If you request blocking, the assembler checks to see whether
there is enough space between the current SPC and the page
boundary. If there is not enough space, the assembler creates
another hole and allocates the space at the beginning of the
next page.
The blocking option allows you to reserve up to 128 words in the .bss section
and ensure that they fit on one page of memory. (Of course, you can reserve
more than 128 words at a time, but they cannot fit on a single page.) The follow-
ing example code reserves two blocks of space in the .bss section.
memptr: .bss A,64,1
memptr1: .bss B,70,1
Each block must be contained within the boundaries of a single page; after the
first block is allocated, however, the second block cannot fit on the current
page. As Figure 4-5 shows, the second block is allocated on the next page.
Unused memory
256
Section directives for initialized sections (.text, .data, and .sect) end the cur-
rent section and begin assembling into another section. The .bss directive,
however, does not affect the current section. The assembler assembles the
.bss directive and then resumes assembling code into the current section. For
more information about COFF sections, see Chapter 2, Introduc-
tion to Common Object File Format.
4-38
Reserve Space in the .bss Section .bss
Example In this example, the .bss directive is used to allocate space for two variables,
TEMP and ARRAY. The symbol TEMP points to 4 words of uninitialized space
(at .bss SPC = 0). The symbol ARRAY points to 100 words of uninitialized
space (at .bss SPC = 04h); this space must be allocated contiguously within
a page. Note that symbols declared with the .bss directive can be referenced
in the same manner as other symbols and can also be declared external.
1 *******************************************
2 ** Assemble into the .text section. **
3 *******************************************
4 000000 .text
5 000000 e800 LD #0, A
6 *******************************************
7 ** Allocate 4 words in .bss for TEMP. **
8 *******************************************
9 000000 Var_1: .bss TEMP, 4
10
11 *******************************************
12 ** Still in .text **
13 *******************************************
14 000001 f000 ADD #56h, A
000002 0056
15 000003 f066 MPY #73h, A
000004 0073
16
17 *******************************************
18 ** Allocate 100 words in .bss for the **
19 ** symbol named ARRAY; this part of **
20 ** .bss must fit on a single page. **
21 *******************************************
22 0000004 .bss ARRAY, 100, 1
23
24 *******************************************
25 ** Assemble more code into .text. **
26 *******************************************
27 000005 8000- STL A, Var_1
28
29 *******************************************
30 ** Declare external .bss symbols. **
31 *******************************************
32 .global ARRAY, TEMP
33 .end
Syntax
.byte value1 [, ... , valuen ]
.ubyte value1 [, ... , valuen ]
.char value1 [, ... , valuen ]
.uchar value1 [, ... , valuen ]
Description The .byte, .ubyte, .char, and .uchar directives place one or more bytes into
consecutive words of the current section. Each byte is placed in a word by
itself; the 8 MSBs are filled with 0s. A value can be:
- An expression that the assembler evaluates and treats as an 8-bit signed
or unsigned number
- A character string enclosed in double quotes. Each character in a string
represents a separate value.
Values are not packed or sign-extended; each byte occupies the 8 least signifi-
cant bits of a full 16-bit word. The assembler truncates values greater than 8
bits. You can use up to 100 value parameters, but the total line length cannot
exceed 200 characters.
If you use a label, it points to the location where the assembler places the first
byte.
Note that when you use these directives in a .struct/.endstruct sequence, they
define a member’s size; they do not initialize memory. For more information
about .struct/.endstruct, see section 4.9, Assembly-Time Symbol Directives,
on page 4-25.
Example In this example, 8-bit values (10, -1, abc, and a) are placed into consecutive
words in memory. The label strx has the value 100h, which is the location of
the first initialized word.
1 0000 .space 100h * 16
2 000100 000a STRX .byte 10, -1, ”abc”, ’a’
000101 00ff
000102 0061
000103 0062
000104 0063
000105 0061
4-40
Conditionally Leave Section Out of COFF Output .clink
Syntax
.clink [”section name“]
Description The .clink directive sets up conditional linking for a section by setting the
STYP_CLINK flag in the type field for section name. The .clink directive can
be applied to initialized or uninitialized sections.
The STYP_CLINK flag tells the linker to leave the section out of the final COFF
output of the linker if there are no references found to any symbol in the
section.
Example In this example, the Vars and Counts sections are set for conditional linking.
1 000000 .sect ”Vars”
2 ; Vars section is conditionally linked
3 .clink
4
5 000000 001A X: .word 01Ah
6 000001 001A Y: .word 01Ah
7 000002 001A Z: .word 01Ah
8 000000 .sect ”Counts”
9 ; Counts section is conditionally linked
10 .clink
11
12 000000 001A Xcount: .word 01Ah
13 000001 001A Ycount: .word 01Ah
14 000002 001A Zcount: .word 01Ah
15 ; By default, .text is unconditionally linked
16 000000 .text
17 ; Reference to symbol X cause the Vars section
18 ; to be linked into the COFF output
19 000000 E800 LD #0, A
20 000001 8000+ STL A, X
Syntax
.c_mode
Description The .c_mode directive is generated as a header for any assembly file created
by the C compiler.
This directive works primarily in conjunction with the -mf assembler option or
the .far_mode directive to facilitate linking a program that uses extended
addressing.
If your program uses extended addressing, but your assembly code was not
generated by the C compiler, you should add the .c_mode directive to your
assembly files.
4-42
Read Source File .copy/.include
Syntax
.copy [”]filename[”]
.include [”]filename[”]
Description The .copy and .include directives tell the assembler to read source state-
ments 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 num-
ber of .list/.nolist directives assembled. The assembler:
3) Resumes assembling statements in the main source file, starting with the
statement that follows the .copy or .include directive.
The filename is a required parameter that names a source file. It may be en-
closed in double quotes and must follow operating system conventions. You
can specify a full pathname (for example, c:\dsp\file1.asm). If you do not speci-
fy a full pathname, the assembler searches for the file in:
For more information about the -i option and A_DIR, see section 3.5, Naming
Alternate Directories for Assembler Input, on page 3-21.
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. An A indicates the
first copied file, B indicates a second copied file, etc.
Example 1 In this example, the .copy directive is used to read and assemble source state-
ments from other files; then the assembler resumes assembling into the cur-
rent 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 re-
maining statement.
Listing file:
1 000000 .space 29
2 .copy ”byte.asm”
A 1 ** In byte.asm
A 2 000002 0020 .byte 32,1+ ’A’
000003 0042
A 3 .copy ”word.asm”
B 1 * In word.asm
B 2 000004 ABCD .word 0ABCDh, 56q
000005 002E
A 4 ** Back in byte.asm
A 5 000006 006A .byte 67h + 3q
3
4 ** Back in original file
5 000007 646F .pstring ”done”
000008 6E65
4-44
Read Source File .copy/.include
Example 2 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 state-
ments are not printed in the listing file.
Listing file:
1 000000 .space 29
2 .include ”byte2.asm”
3
4 ** Back in original file
5 000007 0064 .string ”done”
000008 006F
000009 006E
00000a 0065
Syntax
.csect “section name”
Description The .csect directive defines an initialized, named code section that may con-
tain data-defining directives. The .csect directive begins assembling code into
the section identified by section name. The name must be enclosed in double
quotes.
Normally, the assembler will not accept a section containing both code and
data. However, there are some situations in which data must be defined within
a code section. Such a code section should be created with .csect.
4-46
Assign Character Strings to Substitution Symbols .data
Syntax
.data
Description The .data directive tells the assembler to begin assembling source code into
the .data section; .data becomes the current section. The .data section is
normally used to contain tables of data or preinitialized variables.
The assembler assumes that .text is the default section. Therefore, at the
beginning of an assembly, the assembler assembles code into the .text section
unless you use a section control directive.
For more information about COFF sections, see Chapter 2,
Introduction to Common Object File Format.
Example In this example, code is assembled into the .data and .text sections.
1 *******************************************
2 ** Reserve space in .data. **
3 *******************************************
4 000000 .data
5 000000 .space 0CCh
6
7 *******************************************
8 ** Assemble into .text. **
9 *******************************************
10 000000 .text
11 0000 INDEX .set 0
12 000000 e800 LD #INDEX, A
13
14 *******************************************
15 ** Assemble into .data. **
16 *******************************************
17 00000c Table: .data
18 00000d ffff .word -1 ; Assemble 16-bit
19 ; constant into .data.
20 00000e 00ff .byte 0FFh ; Assemble 8-bit
21 ; constant into .data.
22
23 *******************************************
24 ** Assemble into .text. **
25 *******************************************
26 000001 .text
27 000001 000c” ADD Table, A
28
29 *******************************************
30 ** Resume assembling into the .data **
31 ** section at address 0Fh. **
32 *******************************************
33 00000f .data
Syntax
.double value [, ... , valuen ]
.ldouble value [, ... , valuen ]
Description The .double and .ldouble directives place the IEEE single-precision floating-
point representation of one or more floating-point values into the current
section. Each value must be a floating-point constant or a symbol that has
been equated to a floating-point constant. Each constant is converted to a
floating-point value in IEEE single-precision 32-bit format. Floating-point
constants are aligned on a word boundary.
The value consists of three fields:
Field Meaning
s A 1-bit sign field
f A 23-bit fraction
The value is stored most significant word first, least significant word second,
in the following format:
31 30 23 22 0
s e f
4-48
Specify DP Value .dp
Syntax
.dp dp_value
Description The .dp directive specifies the value of the DP register. The dp_value can be
a constant or a symbolic expression.
The assembler cannot track the value of the DP register; however, it must
know the value of DP in order to assemble direct memory access operands.
Consequently, you must use the .dp directive to model the DP value. Issue this
directive immediately following any instruction that changes the value in the
DP register. If the assembler is not informed of the value of the DP register, it
assumes that the value is 0.
Syntax
.drlist
.drnolist
Description Two directives enable you to control the printing of assembler directives to the
listing file:
The .drlist directive enables the printing of all directives to the listing file.
The .drnolist directive suppresses the printing of the following directives to the
listing file:
- .eval - .mnolist
- .fclist - .sslist
By default, the assembler acts as if the .drlist directive had been specified.
Example This example shows how .drnolist inhibits the listing of the specified directives:
Source file:
.asg 0, x
.loop 2
.eval x+1, x
.endloop
.drnolist
.asg 1, x
.loop 3
.eval x+1, x
.endloop
Listing file:
1 .asg 0, x
2 .loop 2
3 .eval x+1, x
4 .endloop
1 .eval 0+1, x
1 .eval 1+1, x
5
6 .drnolist
7
9 .loop 3
10 .eval x+1, x
11 .endloop
4-50
Define Messages .emsg/.mmsg/.wmsg
Syntax
.emsg string
.mmsg string
.wmsg string
Description These directives allow you to define your own error and warning messages.
The assembler tracks the number of errors and warnings it encounters and
prints these numbers on the last line of the listing file.
The .emsg directive sends error messages to the standard output device in
the same manner as the assembler, incrementing the error count and prevent-
ing the assembler from producing an object file.
The .wmsg directive sends warning messages to the standard output device
in the same manner as the .emsg directive, but it increments the warning count
rather than the error count, and it does not prevent the assembler from produc-
ing an object file.
Source file:
.global PARAM
MSG_EX .macro parm1
.if $symlen(parm1) = 0
.emsg ”ERROR -- MISSING PARAMETER”
.else
add parm1, A
.endif
.endm
MSG_EX PARAM
MSG_EX
Listing file:
1 .global PARAM
2 MSG_EX .macro parm1
3 .if $symlen(parm1) = 0
4 .emsg ”ERROR -- MISSING PARAMETER”
5 .else
6 add parm1, A
7 .endif
8 .endm
9
10 000000 MSG_EX PARAM
1 .if $symlen(parm1) = 0
1 .emsg ”ERROR -- MISSING PARAMETER“
1 .else
1 000000 0000! add PARAM, A
1 .endif
11
12 000001 MSG_EX
1 .if $symlen(parm1) = 0
1 .emsg ”ERROR -- MISSING PARAMETER”
***** USER ERROR ***** - : ERROR -- MISSING PARAMETER
1 .else
1 add parm1, A
1 .endif
4-52
End Assembly .end
Syntax
.end
Description The .end directive is optional and terminates assembly. It should be the last
source statement of a program. The assembler ignores any source statements
that follow a .end directive.
This directive has the same effect as an end-of-file character. You can use .end
when you’re debugging and would like to stop assembling at a specific point
in your code.
Example This example shows how the .end directive terminates assembly. If any source
statements follow the .end directive, the assembler ignores them.
Source File:
START: .space 300
TEMP .set 15
.bss LOC1, 48h
ABS A
ADD #TEMP, A
STL A, LOC1
.end
.byte 4
.word CCCh
Listing file:
1 000000 START: .space 300
2 000F TEMP .set 15
3 000000 .bss LOC1, 48h
4 000013 F485 ABS A
5 000014 F000 ADD #TEMP, A
000015 000F
6 000016 8000- STL A, LOC1
7 .end
Syntax
.far_mode
Description The .far_mode directive tells the assembler that the assembly file uses
extended addressing: calls and branches extend beyond the normal 16-bit
range. This directive has the same effect as using the -mf assembler option.
If your program uses extended addressing, and your assembly code was not
generated by the C compiler, you should add the .c_mode directive to your
assembly files.
4-54
Control the Listing of False Conditional Blocks .fclist/.fcnolist
Syntax
.fclist
.fcnolist
Description Two directives enable you to control the listing of false conditional blocks.
The .fclist directive allows the listing of false conditional blocks (conditional
blocks that do not produce code).
The .fcnolist directive suppresses the listing of false conditional blocks until
a .fclist directive is encountered. With .fcnolist, only code in conditional blocks
that are actually assembled appears in the listing. The .if, .elseif, .else, and
.endif directives do not appear.
By default, all conditional blocks are listed; the assembler acts as if the .fclist
directive had been used.
Example This example shows the assembly language and listing files for code with and
without the conditional blocks listed:
Source File:
AAA .set 1
BBB .set 0
.fclist
.if AAA
ADD #1024, A
.else
ADD #1024*10, A
.endif
.fcnolist
.if AAA
ADD #1024, A
.else
ADD #1024*10, A
.endif
Listing file:
1 0001 AAA .set 1
2 0000 BBB .set 0
3 .fclist
4 .if AAA
5 000000 F000 ADD #1024, A
000001 0400
6 .else
7 ADD #1024*10, A
8 .endif
9
10 .fcnolist
11
13 000002 F000 ADD #1024, A
000003 0400
Syntax
.field value [, size in bits]
Description The .field directive can initialize multiple-bit fields within a single word of
memory. This directive has two operands:
Successive .field directives pack values into the specified number of bits start-
ing at the current word. Fields are packed starting at the most significant part
of the word, moving toward the least significant part as more fields are added.
If the assembler encounters a field size that does not fit into the current word,
it writes out the word, increments the SPC, and begins packing fields into the
next word. You can use the .align directive with an operand of 1 to force the
next .field directive to begin packing into a new word.
If you use a label, it points to the word that contains the specified field.
4-56
Initialize Field .field
Example This example shows how fields are packed into a word. Notice that the SPC
does not change until a word is filled and the next word is begun.
1 ************************************
2 ** Initialize a 14-bit field. **
3 ************************************
4 000000 2AF0 .field 0ABCh, 14
5
6 ************************************
7 ** Initialize a 5-bit field **
8 ** in a new word. **
9 ************************************
10 000001 5000 L_F: .field 0Ah, 5
11
12 ***********************************
13 ** Initialize a 4-bit field **
14 ** in the same word. **
15 ************************************
16 000001 5600 x: .field 0Ch, 4
17
18 ************************************
19 ** 16-bit relocatable field **
20 ** in the next word. **
21 ************************************
22 000002 0001’ .field x
23
24 ************************************
25 ** Initialize a 32-bit field. **
26 ************************************
27 000003 0000 .field 04321h, 32
000004 4321
Figure 4-6 shows how the directives in this example affect memory.
14-bit field
1 0 1 0 1 0
5-bit field
4-bit field
0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 .field x
(d) 1
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .field 04321,32
(e) 3
4 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1
4-58
Initialize Floating-Point Value .float/.xfloat
Syntax
.float value1 [, ... , valuen ]
.xfloat value1 [, ... , valuen ]
Description The .float and .xfloat directives place the floating-point representation of one
or more floating-point constants into the current data section. The value must
be a floating-point constant or a symbol that has been equated to a floating-
point constant. Each constant is converted to a floating-point value in IEEE
single-precision 32-bit format. Floating-point constants are aligned on the
long-word boundaries unless the .xfloat directive is used. The .xfloat directive
performs the same function as the .float directive but does not align the result
on the long word boundary.
Field Meaning
s A 1-bit sign field
f A 23-bit mantissa
The value is stored most significant word first, least significant word second,
in the following format:
31 30 23 22 0
s e f
Syntax
.global symbol1 [, ... , symboln ]
.def symbol1 [, ... , symboln ]
.ref symbol1 [, ... , symboln ]
Description The .global, .def, and .ref directives identify global symbols, which are
defined externally or can be referenced externally.
The .def directive identifies a symbol that is defined in the current module and
can be accessed by other files. The assembler places this symbol in the sym-
bol table.
The .ref directive identifies a symbol that is used in the current module but
defined in another module. The linker resolves this symbol’s definition at link
time.
The .global directive acts as a .ref or a .def, as needed.
A global symbol is defined in the same manner as any other symbol; that is,
it appears as a label or is defined by the .set, .bss, or .usect directive. As with
all symbols, if a global symbol is defined more than once, the linker issues a
multiple-definition error. .ref always creates a symbol table entry for a symbol,
whether the module uses the symbol or not; .global, however, creates an entry
only if the module actually uses the symbol.
A symbol may be declared global for two reasons:
- If the symbol is not defined in the current module (including macro, copy,
and include files), the .global or .ref directive tells the assembler that the
symbol is defined in an external module. This prevents the assembler from
issuing an unresolved reference error. At link time, the linker looks for the
symbol’s definition in other modules.
- If the symbol is defined in the current module, the .global or .def directive
declares that the symbol and its definition can be used externally by other
modules. These types of references are resolved at link time.
Example This example shows four files:
file1.lst and file3.lst are equivalent. Both files define the symbol Init and make
it available to other modules; both files use the external symbols x, y, and z.
file1.lst uses the .global directive to identify these global symbols; file3.lst uses
.ref and .def to identify the symbols.
file2.lst and file4.lst are equivalent. Both files define the symbols x, y, and z
and make them available to other modules; both files use the external symbol
Init. file2.lst uses the .global directive to identify these global symbols; file4.lst
uses .ref and .def to identify the symbols.
4-60
Identify Global Symbols .global/.def/.ref
file1.lst:
1 ; Global symbol defined in this file
2 .global INIT
3 ; Global symbols defined in file2.lst
4 .global X, Y, Z
5 000000 INIT:
6 000000 F000 ADD #56h, A
000001 0056
7 000002 0000! .word X
8 ; .
9 ; .
10 ; .
11 .end
file2.lst:
1 ; Global symbols defined in this file
2 .global X, Y, Z
3 ; Global symbol defined in file1.lst
4 .global INIT
5 0001 X: .set 1
6 0002 Y: .set 2
7 0003 Z: .set 3
8 000000 0000! .word INIT
9 ; .
10 ; .
11 ; .
12 .end
file3.lst:
1 ; Global symbol defined in this file
2 .def INIT
3 ; Global symbols defined in file4.lst
4 .ref X, Y, Z
5 000000 INIT:
6 000000 F000 ADD #56h, A
000001 0056
7 000002 0000! .word X
8 ; .
9 ; .
10 ; .
11 .end
file4.lst:
1 ; Global symbols defined in this file
2 .def X, Y, Z
3 ; Global symbol defined in file3.lst
4 .ref INIT
5 0001 X: .set 1
6 0002 Y: .set 2
7 0003 Z: .set 3
8 000000 0000! .word INIT
9 ; .
10 ; .
11 ; .
12 .end
4-62
Initialize 16-bit Integer .half/.uhalf/.short/.ushort
Syntax
.half value1 [, ... , valuen ]
.uhalf value1 [, ... , valuen ]
.short value1 [, ... , valuen ]
.ushort value1 [, ... , valuen ]
Description The .half, .uhalf, .short, and .ushort directives place one or more values into
consecutive 16-bit fields in the current section. A value can be:
The assembler truncates values greater than 16 bits. You can use as many
values as fit on a single line, but the total line length cannot exceed 200 charac-
ters. If you use a label, it points to the first initialized word.
Example In this example, the .half directive is used to place 16-bit values (10, -1, abc,
and a) into memory; .short is used to place 16-bit values (8, -3, def, and b) into
memory. The label STRN has the value 106h, which is the location of the first
initialized word.
1 000000 .space 100h * 16
2
3 000100 000A .half 10, -1, ”abc”, ’a’
000101 FFFF
000102 0061
000103 0062
000104 0063
000105 0061
4 000106 0008 STRN .short 8, -3, ”def”, ’b’
000107 FFFD
000108 0064
000109 0065
00010a 0066
00010b 0062
5
4-64
Assign Character Strings to Substitution Symbols .if/.elseif/.else/.endif
Syntax
.if well-defined expression
.elseif well-defined expression
.else
.endif
The .if directive marks the beginning of a conditional block. The well-defined
expression is a required parameter, and must be entirely specified on the
same line as the directive.
The .elseif directive identifies a block of code to be assembled when the .if
expression is false (0) and the .elseif expression is true (nonzero). When the
.elseif expression is false, the assembler continues to the next .elseif (if pres-
ent), .else (if present) or .endif (if no .elseif or .else is present). The .elseif di-
rective is optional in the conditional blocks, and more than one .elseif can be
used. If an expression is false and there is no .elseif statement, the assembler
continues with the code that follows a .else (if present) or a .endif.
The .else directive identifies a block of code that the assembler assembles
when the .if expression and all .elseif expressions are false (0). This directive
is optional in the conditional block; if an expression is false and there is no .else
statement, the assembler continues with the code that follows the .endif.
The .elseif and .else directives can be used in the same conditional assembly
block and the .elseif directive can be used more than once within a conditional
assembly block.
4-66
Initialize 16-bit Integer .int/.uint/.word/.uword
Syntax
.int value1 [, ... , valuen ]
.uint value1 [, ... , valuen ]
.word value1 [, ... , valuen ]
.uword value1 [, ... , valuen ]
Description The .int, .uint, .word, and .uword directives are equivalent; they place one
or more values into consecutive 16-bit fields in the current section. A value can
be either:
You can use as many values as fit on a single line (200 characters). If you use
a label, it points to the first word that is initialized.
Example 2 In this example, the .word directive is used to initialize words. The symbol
WordX points to the first word that is reserved.
1 000000 0C80 WORDX: .word 3200, 1 + ’AB’, -0AFh, ’X’
000001 4143
000002 FF51
000003 0058
4-68
Create a Relocatable Label .label
Syntax
.label symbol
Description The .label directive defines a special symbol that refers to the loadtime
address rather than the runtime address within the current section. Most sec-
tions created by the assembler have relocatable addresses. The assembler
assembles each section as if it started at 0, and the linker relocates it to the
address at which it loads and runs.
For some applications, it is desirable to have a section load at one address and
run at a different address. For example, you may wish to load a block of perfor-
mance-critical code into slower off-chip memory to save space, and then move
the code to high-speed on-chip memory to run it.
Such a section is assigned two addresses at link time: a load address and a
run address. All labels defined in the section are relocated to refer to the run-
time address so that references to the section (such as branches) are correct
when the code runs.
The .label directive creates a special label that refers to the loadtime address.
This function is useful primarily to designate where the section was loaded for
purposes of the code that relocates the section.
For more information about assigning runtime and loadtime addresses in the
linker, see section 6.10, Specifying a Section’s Runtime Address, on page
6-48.
Syntax
.length page length
.width page width
Description The .length directive sets the page length of the output listing file. It affects the
current and following pages. You can reset the page length with another
.length directive.
The .width directive sets the page width of the output listing file. It affects the
next line assembled and the lines following; you can reset the page width with
another .width directive.
The width refers to a full line in a listing file; the line counter value, SPC value,
and object code are counted as part of the width of a line. Comments and other
portions of a source statement that extend beyond the page width are trun-
cated in the listing.
The assembler does not list the .width and .length directives.
Example In this example, the page length and width are changed.
*********************************************
** Page length = 65 lines. **
** Page width = 85 characters. **
*********************************************
.length 65
.width 85
*********************************************
** Page length = 55 lines. **
** Page width = 100 characters. **
*********************************************
.length 55
.width 100
4-70
Start/Stop Source Listing .list/.nolist
Syntax
.list
.nolist
Description Two directives enable you to control the printing of the source listing:
- The .nolist directive suppresses the source listing output until a .list
directive is encountered. The .nolist directive can be used to reduce
assembly time and the source listing size. It can be used in macro defini-
tions to suppress the listing of the macro expansion.
The assembler does not print the .list or .nolist directives or the source state-
ments that appear after a .nolist directive. However, it continues to increment
the line counter. You can nest the .list/.nolist directives; each .nolist needs a
matching .list to restore the listing.
By default, the source listing is printed to the listing file; the assembler acts as
if the .list directive had been specified. However, if you don’t request a listing
file when you invoke the assembler, the assembler ignores the .list directive.
Example This example shows how the .copy directive inserts source statements from
another file. The first time this directive is encountered, the assembler lists the
copied source lines in the listing file. The second time this directive is encoun-
tered, the assembler does not list the copied source lines, because a .nolist
directive was assembled. Note that the .nolist, the second .copy, and the .list
directives do not appear in the listing file. Note also that the line counter is
incremented, even when source statements are not listed.
Source file:
.copy ”copy2.asm”
* Back in original file
NOP
.nolist
.copy ”copy2.asm”
.list
* Back in original file
.string ”Done”
Listing file:
1 .copy ”copy2.asm”
A 1 * In copy2.asm (copy file)
A 2 000000 0020 .word 32, 1 + ’A’
000001 0042
2 * Back in original file
3 000002 F495 NOP
7 * Back in original file
8 000005 0044 .string ”Done”
000006 006F
000007 006E
000008 0065
4-72
Allow Maximum localrepeat Loop Size .localalign
Syntax
.localalign symbol
Description The new assembler directive .localalign, meant to be placed right before a
localrepeat instruction, causes the body of the loop to be aligned to a 4-byte
alignment, which will allow the maximum localrepeat loop size. It operates by
inserting a single cycle instruction composed of NOPs of the proper size to get
the alignment correct. It also causes a 4-byte alignment to be applied to the
current section so the linker honors the necessary alignment for that loop body.
It takes no parameters.
Example 1 This example shows the behavior of a localrepeat loop without the .localalign
directive.
main: nop
nop
nop
localrepeat {
ac1 = #5
ac2 = ac1
}
Example 2 This example shows the source code from Example 1 after .localalign is
added.
main: nop
nop
nop
.localalign
localrepeat {
ac1 = #5
ac2 = ac1
}
This example produces an aligned loop body before the localrepeat on line 5,
causing the loop body beginning at line 6 to now be 4-byte aligned; its address
went from 0x5 to 0x8:
1 000000 20 main: nop
2 000001 20 nop
3 000002 20 nop
4 .localalign
5 000006 4A82 localrepeat {
6 000008 3C51 AC1 = #5
7 00000a 2212 AC2 = AC1
8 }
By aligning the loop using the .localalign directive (or even by hand), the local-
repeat loops can achieve maximum size. Without this alignment, the loops
may need to be several bytes shorter due to how the IBQ (Instruction Buffer
Queue) works.
While the directive can be used with short loops, .localalign really only needs
to be used on localrepeat loops that are near the limit of the localrepeat size.
4-74
Initialize Long Word .long/.ulong/.xlong
Syntax
.long value1 [, ... , valuen ]
.ulong value1 [, ... , valuen ]
.xlong value1 [, ... , valuen ]
Description The .long, .ulong, and .xlong directives place one or more 32-bit values into
consecutive words in the current section. The most significant word is stored
first. The .long and .ulong directives align the result on the long word boundary,
while the .xlong directive does not. A value can be:
You can use up to 100 values, but they must fit on a single source statement
line. If you use a label, it points to the first word that is initialized.
Example This example shows how the .long and .xlong directives initialize double
words.
1 000000 0000 DAT1: .long 0ABCDh, ’A’ + 100h, ’g’, ’o’
000001 ABCD
000002 0000
000003 0141
000004 0000
000005 0067
000006 0000
000007 006F
2 000008 0000’ .xlong DAT1, 0AABBCCDDh
000009 0000
00000a AABB
00000b CCDD
3 00000c DAT2:
4-76
Assign Character Strings to Substitution Symbols .loop/.break/.endloop
Syntax
.loop [well-defined expression]
.break [well-defined expression]
.endloop
The .loop directive begins a repeatable block of code. The optional expression
evaluates to the loop count (the number of times to repeat the assembly of the
code contained in the loop). If there is no expression, the loop count defaults
to 1024, unless the assembler first encounters a .break directive with an ex-
pression that is true (nonzero) or omitted.
The .break directive is optional, along with its expression. When the expres-
sion is false (0), the loop continues. When the expression is true (nonzero),
or omitted, the assembler breaks the loop and assembles the code after the
.endloop directive.
Example This example illustrates how these directives can be used with the .eval
directive.
1 .eval 0,x
2 COEF .loop
3 .word x*100
4 .eval x+1, x
5 .break x = 6
6 .endloop
1 000000 0000 .word 0*100
1 .eval 0+1, x
1 .break 1 = 6
1 000001 0064 .word 1*100
1 .eval 1+1, x
1 .break 2 = 6
1 000002 00C8 .word 2*100
1 .eval 2+1, x
1 .break 3 = 6
1 000003 012C .word 3*100
1 .eval 3+1, x
1 .break 4 = 6
1 000004 0190 .word 4*100
1 .eval 4+1, x
1 .break 5 = 6
1 000005 01F4 .word 5*100
1 .eval 5+1, x
1 .break 6 = 6
Syntax
macname .macro [parameter1 ] [, ... parametern ]
model statements or macro directives
.endm
You can define a macro anywhere in your program, but you must define the
macro before you can use it. Macros can be defined at the beginning of a
source file, in an .include/.copy file, or in a macro library.
macname names the macro. You must place the name in the
source statement’s label field.
4-78
Define Macro Library .mlib
Syntax
.mlib [”]filename[”]
Description The .mlib directive provides the assembler with the name of a macro library.
A macro library is a collection of files that contain macro definitions. These files
are bound into a single file (called a library or archive) by the archiver. Each
member of a macro library may contain one macro definition that corresponds
to the name of the file. Macro library members must be source files (not object
files).
The filename of a macro library member must be the same as the macro name,
and its extension must be .asm. The filename must follow host operating sys-
tem conventions; it may be enclosed in double quotes. You can specify a full
pathname (for example, c:\dsp\macs.lib). If you do not specify a full pathname,
the assembler searches for the file in:
1) The directory that contains the current source file
2) Any directories named with the -i assembler option
3) Any directories specified by the environment variable A_DIR
For more information about the -i option and the environment variable, see
section 3.5, Naming Alternate Directories for Assembler Input, on page 3-21.
When the assembler encounters a .mlib directive, it opens the library and
creates a table of the library’s contents. The assembler enters the names of
the individual library members into the opcode table as library entries. This re-
defines any existing opcodes or macros that have the same name. If one of
these macros is called, the assembler extracts the entry from the library and
loads it into the macro table. The assembler expands the library entry in the
same way it expands other macros, but it does not place the source code into
the listing. Only macros that are actually called from the library are extracted,
and they are extracted only once.
Example This example creates a macro library that defines two macros, incr and decr.
The file incr.asm contains the definition of incr, and decr.asm contains the defi-
nition of decr.
incr.asm decr.asm
* Macro for incrementing * Macro for zero accumulators
incr .macro decr .macro
ADD #1,A SUB A,A
ADD #1,B SUB B,B
.endm .endm
Now you can use the .mlib directive to reference the macro library and define
the incr and decr macros:
1 .mlib ”mac.lib”
2 000000 decr ; Macro call
1 000000 F420 SUB A,A
1 000001 F720 SUB B,B
3 000002 incr ; Macro call
1 000002 F000 ADD #1,A
000003 0001
1 000004 F300 ADD #1,B
000005 0001
4-80
Start/Stop Expansion Listing .mlist/.mnolist
Syntax
.mlist
.mnolist
Description Two directives enable you to control the listing of macro and repeatable block
expansions in the listing file:
- The .mlist directive allows macro and .loop/.endloop block expansions in
the listing file.
- The .mnolist directive suppresses macro and .loop/.endloop block
expansions in the listing file.
By default, the assembler behaves as if the .mlist directive had been specified.
Example This example defines a macro named STR_3. The second time the macro is
called, the macro expansion is not listed, because a .mnolist directive was
assembled. The third time the macro is called, the macro expansion is listed,
because a .mlist directive was assembled.
1 STR_3 .macro P1, P2, P3
2 .string ”:p1:”, ”:p2:”, ”:p3:”
3 .endm
4
5 000000 STR_3 ”as”, ”I”, ”am”
1 000000 003A .string ”:p1:”, ”:p2:”, ”:p3:”
000001 0070
000002 0031
000003 003A
000004 003A
000005 0070
000006 0032
000007 003A
000008 003A
000009 0070
00000a 0033
00000b 003A
6 .mnolist
7 00000c STR_3 ”as”, ”I”, ”am”
8 .mlist
9 000018 STR_3 ”as”, ”I”, ”am”
1 000018 003A .string ”:p1:”, ”:p2:”, ”:p3:”
000019 0070
00001a 0031
00001b 003A
00001c 003A
00001d 0070
00001e 0032
00001f 003A
000020 003A
000021 0070
000022 0033
000023 003A
Syntax
.mmregs
Description The .mmregs directive defines global symbolic names for the C54x registers
and places them in the global symbol table. It is equivalent to executing AL .set
8, AH .set 9, etc. The symbols are local and absolute. Using the .mmregs
directive makes it unnecessary to define these symbols.
Hexadecimal
Name Address Description
IMR 0000 Interrupt mask register
- 2-5 Reserved
Note: Duplication of address values in the table supports the different names of the registers
as they are implemented on different C54x devices.
4-82
Assign Memory-Mapped Register Names as Global Symbols .mmregs
Hexadecimal
Name Address Description
BDDR0 0020 BSP0 data receive register
Note: Duplication of address values in the table supports the different names of the registers
as they are implemented on different C54x devices.
Hexadecimal
Name Address Description
SPC1 0032 Serial port control register 1
Note: Duplication of address values in the table supports the different names of the registers
as they are implemented on different C54x devices.
4-84
Assign Memory-Mapped Register Names as Global Symbols .mmregs
Syntax
.mmregs
Description The .mmregs directive defines global symbolic names for the C54x registers
and places them in the global symbol table. It is equivalent to executing AC0L
.set 8, AC0H .set 9, etc. The symbols are local and absolute. Using the
.mmregs directive makes it unnecessary to define these symbols.
Syntax
.newblock
Description The .newblock directive undefines any local labels currently defined. Local
labels, by nature, are temporary; the .newblock directive resets them and
terminates their scope.
A local label is a label in the form $n, where n is a single decimal digit. A local
label, like other labels, points to an instruction word. Unlike other labels, local
labels cannot be used in expressions. Local labels are not included in the
symbol table.
After a local label has been defined and (perhaps) used, you should use the
.newblock directive to reset it. The .text, .data, and named sections also reset
local labels. Local labels that are defined within an include file are not valid out-
side of the local file.
Example This example shows how the local label $1 is declared, reset, and then
declared again.
1 .ref ADDRA, ADDRB, ADDRC
2 0076 B .set 76h
3
4 000000 1000! LABEL1: LD ADDRA, A
5 000001 F010 SUB #B, A
000002 0076
6 000003 F843 BC $1, ALT
000004 0008’
7 000005 1000! LD ADDRB, A
8 000006 F073 B $2
000007 0009’
9
10 000008 1000! $1 LD ADDRA, A
11 000009 0000! $2 ADD ADDRC, A
12 .newblock ; Undefine $1 to reuse
13 00000a F843 BC $1, ALT
00000b 000D’
14 00000c 8000! STL A, ADDRC
15 00000d F495 $1 NOP
4-86
Control Remarks .noremark/.remark
Syntax
.noremark num
.remark [num]
Description The .noremark directive suppresses the assembler remark identified by num.
A remark is an informational assembler message that is less severe than a
warning.
Syntax
.option option list
Description The .option directive selects several options for the assembler output listing.
Option list is a list of options separated by vertical lines; each option selects
a listing feature. These are valid options:
4-88
Select Listing Options .option
Example This example shows how to limit the listings of the .byte, .word, .long, and
.string directives to one line each.
1 ****************************************
2 ** Limit the listing of .byte, .word, **
3 ** .long, and .string directives **
4 ** to 1 line each. **
5 ****************************************
6 .option B, W, L, T
7 000000 00BD .byte -’C’, 0B0h, 5
8 000004 AABB .long 0AABBCCDDh, 536 + ’A’
9 000008 15AA .word 5546, 78h
10 00000a 0045 .string ”Extended Registers”
11
12 ****************************************
13 ** Reset the listing options. **
14 ****************************************
15 .option R
16 00001c 00BD .byte -’C’, 0B0h, 5
00001d 00B0
00001e 0005
17 000020 AABB .long 0AABBCCDDh, 536 + ’A’
000021 CCDD
000022 0000
000023 0259
18 000024 15AA .word 5546, 78h
000025 0078
19 000026 0045 .string ”Extended Registers”
000027 0078
000028 0074
000029 0065
00002a 006E
00002b 0064
00002c 0065
00002d 0064
00002e 0020
00002f 0052
000030 0065
000031 0067
000032 0069
000033 0073
000034 0074
000035 0065
000036 0072
000037 0073
Syntax
.page
Description The .page directive produces a page eject in the listing file. The .page directive
is not printed in the source listing, but the assembler increments the line
counter when it encounters it. Using the .page directive to divide the source
listing into logical divisions improves program readability.
Example This example shows how the .page directive causes the assembler to begin
a new page of the source listing.
Source file:
.title ”**** Page Directive Example ****”
; .
; .
; .
.page
Listing file:
TMS320C54x COFF Assembler Version x.xx
Copyright (c) 2001 Texas Instruments Incorporated
**** Page Directive Example **** PAGE 1
2 ; .
3 ; .
4 ; .
TMS320C54x COFF Assembler Version x.xx
Copyright (c) 2001 Texas Instruments Incorporated
**** Page Directive Example **** PAGE 2
4-90
Specify Blocking for an Initialized Section .sblock
Syntax
.sblock [”]section name[”] [, ”section name”, . . . ]
Description The .sblock directive designates sections for blocking. Blocking is an address
alignment mechanism similar to page alignment, but weaker. A blocked
section is guaranteed to not cross a page boundary (128 words) if it is smaller
than a page, or to start on a page boundary if it is larger than a page. This
directive allows specification of blocking for initialized sections only, not
uninitialized sections declared with .usect or the .bss directives. The section
names may optionally be enclosed in quotes.
Example This example designates the .text and .data sections for blocking.
1 ****************************************
2 ** Specify blocking for the .text **
3 ** and .data sections. **
4 ****************************************
5 .sblock .text, .data
Syntax
.sect ”section name”
Description The .sect directive defines a named section that can be used like the default
.text and .data sections. The .sect directive begins assembling source code
into the named section.
The section name identifies a section that the assembler assembles code into.
The name can be up to 200 characters and must be enclosed in double quotes.
A section name can contain a subsection name in the form section name:sub-
section name. For COFF1 formatted files, only the first 8 characters are signifi-
cant.
Example This example defines a special-purpose section named Vars and assembles
code into it.
1 **********************************************
2 ** Begin assembling into .text section. **
3 **********************************************
4 000000 .text
5 000000 E878 LD #78h, A ; Assembled into .text
6 000001 F000 ADD #36h, A ; Assembled into .text
000002 0036
7 **********************************************
8 ** Begin assembling into Vars section. **
9 **********************************************
10 000000 .sect ”Vars”
11 0010 WORD_LEN .set 16
12 0020 DWORD_LEN .set WORD_LEN * 2
13 0008 BYTE_LEN .set WORD_LEN / 2
14 **********************************************
15 ** Resume assembling into .text section. **
16 **********************************************
17 000003 .text
18 000003 F000 ADD #42h, A ; Assembled into .text
000004 0042
19 000005 0003 .byte 3, 4 ; Assembled into .text
000006 0004
20 **********************************************
21 ** Resume assembling into Vars section. **
22 **********************************************
23 000000 .sect ”Vars”
24 000000 000D .field 13, WORD_LEN
25 000001 0A00 .field 0Ah, BYTE_LEN
26 000002 0000 .field 10q, DWORD_LEN
000003 0008
27
4-92
Define Assembly-Time Constant .set/.equ
Syntax
symbol .set value
symbol .equ value
Description The .set and .equ directives equate a value to a symbol. The symbol can then
be used in place of a value in assembly source. This allows you to equate
meaningful names with constants and other values.
- The symbol is a label that must appear in the label field.
- The value must be a well-defined expression; that is, all symbols in the
expression must be previously defined in the current source module.
Undefined external symbols and symbols that are defined later in the module
cannot be used in the expression. If the expression is relocatable, the symbol
to which it is assigned is also relocatable.
The value of the expression appears in the object field of the listing. This value
is not part of the actual object code and is not written to the output file.
Symbols defined with .set or .equ can be made externally visible with the .def
or .global directive. In this way, you can define global absolute constants.
Example This example shows how symbols can be assigned with .set and .equ.
1 **********************************************
2 ** Equate symbol AUX_R1 to register AR1 **
3 ** and use it instead of the register. **
4 **********************************************
5 0011 AUX_R1 .set AR1
6 000000 7711 STM #56h, AUX_R1
000001 0056
7
8 **********************************************
9 ** Set symbol index to an integer expr. **
10 ** and use it as an immediate operand. **
11 **********************************************
12 0035 INDEX .equ 100/2 +3
13 000002 F000 ADD #INDEX, A
000003 0035
14
15 **********************************************
16 ** Set symbol SYMTAB to a relocatable expr. **
17 ** and use it as a relocatable operand. **
18 **********************************************
19 000004 000A LABEL .word 10
20 0005’ SYMTAB .set LABEL + 1
21
22 **********************************************
23 ** Set symbol NSYMS equal to the symbol **
24 ** INDEX and use it as you would INDEX. **
25 **********************************************
26 0035 NSYMS .set INDEX
27 000005 0035 .word NSYMS
Syntax
.space size in bits
.bes size in bits
Description The .space and .bes directives reserve size number of bits in the current sec-
tion and fill them with 0s.
When you use a label with the .space directive, it points to the first word
reserved. When you use a label with the .bes directive, it points to the last word
reserved.
Example This example shows how memory is reserved with the .space and .bes
directives.
1 *********************************************
2 ** Begin assembling into .text section. **
3 *********************************************
4 000000 .text
5
6 *********************************************
7 ** Reserve 0F0 bits (15 words in the **
8 ** .text section). **
9 *********************************************
10 000000 .space 0F0h
11 00000f 0100 .word 100h, 200h
000010 0200
12 *********************************************
13 ** Begin assembling into .data section. **
14 *********************************************
15 000000 .data
16 000000 0049 .string ”In .data”
000001 006E
000002 0020
000003 002E
000004 0064
000005 0061
000006 0074
000007 0061
17 *********************************************
18 ** Reserve 100 bits in the .data section; **
19 ** RES_1 points to the first word that **
20 ** contains reserved bits. **
21 *********************************************
22 000008 RES_1: .space 100
23 00000f 000F .word 15
24 000010 0008” .word RES_1
25
26 *********************************************
27 ** Reserve 20 bits in the .data section; **
28 ** RES_2 points to the last word that **
29 ** contains reserved bits. **
30 *********************************************
31 000012 RES_2: .bes 20
32 000013 0036 .word 36h
33 000014 0012” .word RES_2
4-94
Control Listing of Substitution Symbols .sslist/.ssnolist
Syntax
.sslist
.ssnolist
Description Two directives enable you to control substitution symbol expansion in the
listing file:
- The .sslist directive allows substitution symbol expansion in the listing file.
The expanded line appears below the actual source line.
By default, all substitution symbol expansion in the listing file is inhibited. Lines
with the pound (#) character denote expanded substitution symbols.
Example This example shows code that, by default, suppresses the listing of substitu-
tion symbol expansion, and it shows the .sslist directive assembled, instructing
the assembler to list substitution symbol code expansion.
(a) Mnemonic example
1 000000 .bss ADDRX, 1
2 000001 .bss ADDRY, 1
3 000002 .bss ADDRA, 1
4 000003 .bss ADDRB, 1
5 ADD2 .macro ADDRA, ADDRB
6 LD ADDRA, A
7 ADD ADDRB, A
8 STL A, ADDRB
9 .endm
10
11 0000008094 STL A, *AR4+
12 000001 ADD2 ADDRX, ADDRY
1 0000011000- LD ADDRX, A
1 0000020001- ADD ADDRY, A
1 0000038001- STL A, ADDRY
13
14 .sslist
15
16 000004 8094 STL A, *AR4+
17 000005 8090 STL A, *AR0+
18
19 000006 ADD2 ADDRX, ADDRY
1 0000061000- LD ADDRA, A
# LD ADDRX, A
1 0000070001- ADD ADDRB, A
# ADD ADDRY, A
1 0000088001- STL A, ADDRB
# STL A, ADDRY
4-96
Initialize Text .string/.pstring
Syntax
.string ”string1 ” [, ... , ”stringn ”]
.pstring ”string1 ” [, ... , ”stringn ”]
Description The .string and .pstring directives place 8-bit characters from a character
string into the current section. With the .string directive, each 8-bit character
has its own 16-bit word, but with the .pstring directive, the data is packed so
that each word contains two 8-bit bytes. Each string is either:
- An expression that the assembler evaluates and treats as a 16-bit signed
number, or
- A character string enclosed in double quotes. Each character in a string
represents a separate byte.
With .pstring, values are packed into words starting with the most significant
byte of the word. Any unused space is padded with null bytes.
The assembler truncates any values that are greater than 8 bits. You may have
up to 100 operands, but they must fit on a single source statement line.
If you use a label, it points to the location of the first word that is initialized.
Note that when you use .string in a .struct/.endstruct sequence, .string defines
a member’s size; it does not initialize memory. For more information about
.struct/.endstruct, see section 4.9, Assembly-Time Symbol Directives, on
page 4-25.
Example This example shows 8-bit values placed into words in the current section.
1 000000 0041 Str_Ptr: .string ”ABCD”
000001 0042
000002 0043
000003 0044
2 000004 0041 .string 41h, 42h, 43h, 44h
000005 0042
000006 0043
000007 0044
3 000008 4175 .pstring ”Austin”, ”Houston”
000009 7374
00000a 696E
00000b 486F
00000c 7573
00000d 746F
00000e 6E00
4 00000f 0030 .string 36 + 12
Syntax
[ stag ] .struct [ expr ]
[ mem0 ] element [ expr0 ]
[ mem1 ] element [ expr1 ]
. . .
. . .
. . .
[ memn ] .tag stag [, exprn ]
. . .
. . .
. . .
[ memN ] element [ exprN ]
[ size ] .endstruct
label .tag stag
Description The .struct directive assigns symbolic offsets to the elements of a data
structure definition. This enables you to group similar data elements together
and then let the assembler calculate the element offset. This is similar to a C
structure or a Pascal record. A .struct definition may contain a .union definition,
and .structs and .unions may be nested. The .struct directive does not allocate
memory; it merely creates a symbolic template that can be used repeatedly.
stag is the structure’s tag. Its value is associated with the beginning
of the structure. If no stag is present, the assembler puts the
structure members in the global symbol table with the value of
their absolute offset from the top of the structure. Stag is optional
for .struct, but required for .tag.
expr is an optional expression indicating the beginning offset of the
structure. Structures default to start at 0. This parameter can only
be used with a top-level structure. It cannot be used when
defining a nested structure.
4-98
Declare Structure Type .struct/.endstruct/.tag
These examples show various uses of the .struct, .tag, and .endstruct
directives.
Example 1
1 REAL_REC .struct ; stag
2 0000 NOM .int ; member1 = 0
3 0001 DEN .int ; member2 = 1
4 0002 REAL_LEN .endstruct ; real_len = 2
5
6 000000 0001- ADD REAL + REAL_REC.DEN, A
7 ; access structure element
8
9 000000 .bss REAL, REAL_LEN ; allocate mem rec
Example 2
10 CPLX_REC .struct ; stag
11 0000 REALI .tag REAL_REC ; member1 = 0
12 0002 IMAGI .tag REAL_REC
13 0004 CPLX_LEN .endstruct ; cplx_len = 4
14
15 COMPLEX .tag CPLX_REC ; assign structure attrib
16
17 000002 .bss COMPLEX, CPLX_LEN
18
19 000001 0002- ADD COMPLEX.REALI, A ; access structure
20 000002 8002- STL A, COMPLEX.REALI
21
22 000003 0104- ADD COMPLEX.IMAGI, B ; allocate space
Example 3
1 .struct ; no stag puts mems into
2 ; global symbol table
3 0000 X .int ; create 3 dim templates
4 0001 Y .int
5 0002 Z .int
6 0003 .endstruct
Example 4
1 BIT_REC .struct ; stag
2 0000 STREAM .string 64
3 0040 BIT7 .field 7 ; bits1 = 64
4 0040 BIT9 .field 9 ; bits2 = 64
5 0041 BIT10 .field 10 ; bits3 = 65
6 0042 X_INT .int ; x_int = 66
7 0043 BIT_LEN .endstruct ; length = 67
8
9 BITS .tag BIT_REC
10 000000 0040- ADD BITS.BIT7, A ; move into acc
11 000001 f030 AND #007Fh, A ; mask off garbage bits
000002 007f
12
13 000000 .bss BITS, BIT_REC
4-100
Define Tab Size .tab
Syntax
.tab size
Description The .tab directive defines the tab size. Tabs encountered in the source input
are translated to size spaces in the listing. The default tab size is eight spaces.
Example Each of the following lines consists of a single tab character followed by an
NOP instruction.
Source file:
; default tab size
NOP
NOP
NOP
.tab 4
NOP
NOP
NOP
.tab 16
NOP
NOP
NOP
Listing file:
1 ; default tab size
2 000000 F495 NOP
3 000001 F495 NOP
4 000002 F495 NOP
5
7 000003 F495 NOP
8 000004 F495 NOP
9 000005 F495 NOP
10
12 000006 F495 NOP
13 000007 F495 NOP
14 000008 F495 NOP
Syntax
.text
Description The .text directive tells the assembler to begin assembling into the .text
section, which usually contains executable code. The section program counter
is set to 0 if nothing has yet been assembled into the .text section. If code has
already been assembled into the .text section, the section program counter is
restored to its previous value in the section.
.text is the default section. Therefore, at the beginning of an assembly, the
assembler assembles code into the .text section unless you specify a different
sections directive (.data or .sect).
For more information about COFF sections, see Chapter 2,
Introduction to Common Object File Format.
Example This example assembles code into the .text and .data sections. The .data sec-
tion contains integer constants, and the .text section contains executable
code.
1 *****************************************
2 ** Begin assembling into .data section.**
3 *****************************************
4 000000 .data
5 000000 000a .byte 0Ah, 0Bh
000001 000b
6
7 ******************************************
8 ** Begin assembling into .text section. **
9 ******************************************
10 000000 .text
11 000000 0041 START: .string ”A”,”B”,”C”
000001 0042
000002 0043
12 000003 0058 END: .string ”X”,”Y”,”Z”
000004 0059
000005 005a
13
14 000006 0000’ ADD START, A
15 000007 0003’ ADD END, A
16 *******************************************
17 ** Resume assembling into .data section.**
18 *******************************************
19 000002 .data
20 000002 000c .byte 0Ch, 0Dh
000003 000d
21 *******************************************
22 ** Resume assembling into .text section.**
23 *******************************************
24 000008 .text
25 000008 0051 .string ”Quit”
000009 0075
00000a 0069
00000b 0074
4-102
Define Page Title .title
Syntax
.title ”string”
Description The .title directive supplies a title that is printed in the heading on each listing
page. The source statement itself is not printed, but the line counter is increm-
ented.
The assembler prints the title on the page that follows the directive, and on sub-
sequent pages until another .title directive is processed. If you want a title on
the first page, the first source statement must contain a .title directive.
Example In this example, one title is printed on the first page and a different title on
succeeding pages.
Source file:
.title ”**** Fast Fourier Transforms ****”
; .
; .
; .
.title ”**** Floating-Point Routines ****”
.page
Listing file:
COFF Assembler Version x.xx
Copyright (c) 2001 Texas Instruments Incorporated
**** Fast Fourier Transforms **** PAGE 1
2 ; .
3 ; .
4 ; .
COFF Assembler Version x.xx
Copyright (c) 2001 Texas Instruments Incorporated
**** Floating-Point Routines **** PAGE 2
Syntax
[ utag ] .union [ expr ]
[ mem0 ] element [ expr0 ]
[ mem1 ] element [ expr1 ]
. . .
. . .
. . .
[ memn ] .tag utagn [, exprn ]
. . .
. . .
. . .
[ memN ] element [ exprN ]
[ size ] .endunion
label .tag utag
Description The .union directive assigns symbolic offsets to the elements of alternate data
structure definitions to be allocated in the same memory space. This enables
you to define several alternate structures and then let the assembler calculate
the element offset. This is similar to a C union. The .union directive does not
allocate any memory; it merely creates a symbolic template that can be used
repeatedly.
A .struct definition may contain a .union definition, and .structs and .unions
may be nested.
4-104
Declare Union Type .union/.endunion/.tag
utag is the union’s tag. Its value is associated with the beginning of the
union. If no utag is present, the assembler puts the union
members in the global symbol table with the value of their abso-
lute offset from the top of the union. In this case, each member
must have a unique name.
expr is an optional expression indicating the beginning offset of the
union. Unions default to start at 0. This parameter can only be
used with a top-level union. It cannot be used when defining a
nested union.
memn is an optional label for a member of the union. This label is abso-
lute and equates to the present offset from the beginning of the
union. A label for a union member cannot be declared global.
element is one of the following descriptors: .byte, .char, .double, field,
.float, .half, .int, .long, .short, .string, .ubyte, .uchar, .uhalt, .uint,
.ulong, .ushort, .uword, and .word. An element can also be a com-
plete declaration of a nested structure or union, or a structure or
union declared by its tag. Following a .union directive, these
directives describe the element’s size. They do not allocate
memory.
exprn is an optional expression for the number of elements described.
This value defaults to 1. A .string element is considered to be one
word in size, and a .field element is one bit.
size is an optional label for the total size of the union.
Example 1
1 .global employid
2 xample .union ; utag
3 0000 ival .word ; member1 = int
4 0000 fval .float ; member2 = float
5 0000 sval .string ; member3 = string
6 0002 real_len .endunion ; real_len = 2
7
8 000000 .bss employid, real_len ;allocate memory
9
10 employid .tag xample ; name an instance
11 000000 0000- ADD employid.fval, A ; access union element
Example 2
1
2 .union ; utag
3 0000 x .long ; member1 = long
4 0000 y .float ; member2 = float
5 0000 z .word ; member3 = word
6 0002 size_u .endunion ; real_len = 2
7
4-106
Reserve Uninitialized Space .usect
Syntax
symbol .usect ”section name”, size in words [, [blocking flag] [, alignment]]
Description The .usect directive reserves space for variables in an uninitialized, named
section. This directive is similar to the .bss directive; both simply reserve space
for data and have no contents. However, .usect defines additional sections
that can be placed anywhere in memory, independently of the .bss section.
symbol points to the first location reserved by this invocation of the
.usect directive. The symbol corresponds to the name of
the variable for which you’re reserving space.
section name must be enclosed in double quotes. This parameter
names the uninitialized section. The name can be up to
200 characters. For COFF1 formatted files, only the first
8 characters are significant. A section name can contain
a subsection name in the form section name:subsection
name.
size in words is an expression that defines the number of words that are
reserved in section name.
blocking flag is an optional parameter. If specified and nonzero, the flag
means that this section will be blocked. Blocking is an ad-
dress mechanism similar to alignment, but weaker. It
means a section is guaranteed to not cross a page bound-
ary (128 words) if it is smaller than a page, and to start on
a page boundary if it is larger than a page. This blocking
applies to the section, not to the object declared with this
instance of the .usect directive.
alignment is an optional parameter that ensures that the space allo-
cated to the symbol occurs on the specified boundary. This
boundary indicates the size of the slot in words and can be
set to any power of 2.
Other sections directives (.text, .data, and .sect) end the current section and
tell the assembler to begin assembling into another section. The .usect and the
.bss directives, however, do not affect the current section. The assembler
assembles the .usect and the .bss directives and then resumes assembling
into the current section.
4-108
Reserve Uninitialized Space .usect
100 words
dflag
50 words
Syntax
.var sym1 [,sym2 , ... , symn ]
Description The .var directive allows you to use substitution symbols as local variables
within a macro. With this directive, you can define up to 32 local macro sub-
stitution symbols (including parameters) per macro.
The .var directive creates temporary substitution symbols with the initial value
of the null string. These symbols are not passed in as parameters, and they
are lost after expansion.
4-110
Suppress Warning Messages .warn_off/.warn_on
Syntax
.warn_off
.warn_on
Description The .warn_off and .warn_on directives control the reporting of assembler
warning messages. By default (.warn_on), the assembler will generate
warning messages. The .warn_off directive suppresses assembler warning
messages and is equivalent to using the -mw command line option. In the
case of a conflict between the command line option and the directive, the
directive takes precedence.
The .warn_off and .warn_on directives can be used to toggle this behavior for
regions of an assembly file.
The scope of the .warn_off and .warn_on directives is static and not subject
to the control flow of the assembly program. Warnings will not be reported for
any assembly code between the .warn_off and .warn_on directives within a
file.
Syntax
.version value
Description The .version directive determines for which processor instructions are built.
Use one of the following for value:
541
542
543
545
545LP
546LP
548
54_ext (for all other C54x devices with extended program space)
4-112
Chapter 5
Macro Language
The assembler supports a macro language that enables you to create your
own instructions. This is especially useful when a program executes a
particular task several times. The macro language lets you:
- Define your own macros and redefine existing macros
- Simplify long or complicated assembly code
- Access macro libraries created with the archiver
- Define conditional and repeatable blocks within a macro
- Manipulate strings within a macro
- Control expansion listing
Topic Page
5-1
Using Macros
If you want to call a macro several times, but with different data each time, you
can assign parameters within a macro. This enables you to pass different
information to the macro each time you call it. The macro language supports
a special symbol called a substitution symbol, which is used for macro
parameters.
Step 1: Define the macro. You must define macros before you can use them
in your program. There are two methods for defining macros:
- Macros can be defined at the beginning of a source file or in a
.copy/.include file. See Section 5.2, Defining Macros, for more
information.
- Macros can be defined in a macro library. A macro library is a col-
lection of files in archive format created by the archiver. Each
member of the archive file (macro library) contains one macro
definition corresponding to the member name. You can access
a macro library by using the .mlib directive. See Section 5.4,
Macro Libraries, on page 5-14 for more information.
Step 2: Call the macro. After defining a macro, you call it by using the macro
name as a mnemonic in the source program. This is referred to as
a macro call.
Step 3: Expand the macro. The assembler expands your macros when the
source program calls them. During expansion, the assembler
passes arguments by variable to the macro parameters, replaces
the macro call statement with the macro definition, and assembles
the source code. By default, the macro expansions are printed in the
listing file. You can turn off expansion listing by using the .mnolist
directive. See Section 5.8, Formatting the Output Listing, on page
5-22 for more information.
When the assembler encounters a macro definition, it places the macro name
in the opcode table. This redefines any previously defined macro, library entry,
directive, or instruction mnemonic that has the same name as the macro. This
allows you to expand the functions of directives and instructions, as well as to
add new instructions.
5-2
Defining Macros
Macro definitions can be nested, and they can call other macros, but all
elements of any macro must be defined in the same file. Nested macros are
discussed in Section 5.9, Using Recursive and Nested Macros, on page 5-23.
macname names the macro. You must place the name in the
source statement’s label field. Only the first 32
characters of a macro name are significant. The
assembler places the macro name in the internal
opcode table, replacing any instruction or previous
macro definition with the same name.
If you want to include comments with your macro definition but do not want
those comments to appear in the macro expansion, use an exclamation point
to precede your comments. If you do want your comments to appear in the
macro expansion, use an asterisk or semicolon. For more information about
macro comments, see Section 5.7, Producing Messages in Macros, on page
5-20.
1 *
2
3 * add3
4 *
5 * ADDRP = P1 + P2 + P3
6
7 add3 .macro P1, P2, P3, ADDRP
8
9 LD P1, A
10 ADD P2, A
11 ADD P3, A
12 STL A, ADDRP
13 .endm
14
15
16 .global abc, def, ghi, adr
17
18 000000 add3 abc, def, ghi, adr
1
1 000000 1000! LD abc, A
1 000001 0000! ADD def, A
1 000002 0000! ADD ghi, A
1 000003 8000! STL A, adr
5-4
Defining Macros
1 *
2
3 * add3
4 *
5 * ADDRP = P1 + P2 + P3
6
7 add3 .macro P1, P2, P3, ADDRP
8
9 A = @P1
10 A = A + @P2
11 A = A + @P3
12 @ADDRP = A
13 .endm
14
15
16 .global abc, def, ghi, adr
17
18 000000 add3 abc, def, ghi, adr
1
1 000000 1000! A = @abc
1 000001 0000! A = A + @def
1 000002 0000! A = A + @ghi
1 000003 8000! @adr = A
Valid substitution symbols can be up to 32 characters long and must begin with
a letter. The remainder of the symbol can be a combination of alphanumeric
characters, underscores, and dollar signs.
Substitution symbols used as macro parameters are local to the macro they
are defined in. You can define up to 32 local substitution symbols (including
substitution symbols defined with the .var directive) per macro. For more
information about the .var directive, see subsection 5.3.6, Substitution
Symbols as Local Variables in Macros, on page 5-13.
At assembly time, the assembler replaces the substitution symbol with its
corresponding character string, then translates the source code into object
code.
5-6
Macro Parameters/Substitution Symbols
Macro definition
Parms .macro a,b,c
; a = :a:
; b = :b:
; c = :c:
.endm
Parms ”””string”””,x,y
; a = ”string”
; b = x
; c = y
The quotation marks are optional. If there are no quotation marks, the
assembler reads characters up to the first comma and removes leading and
trailing blanks. In either case, a character string is read and assigned to the
substitution symbol.
The .eval directive evaluates the expression and assigns the string value of
the result to the substitution symbol. If the expression is not well defined, the
assembler generates an error and assigns the null string to the symbol.
.asg 1,counter
.loop 100
.word counter
.eval counter + 1,counter
.endloop
In Example 5-4 the .asg directive could be replaced with the .eval directive
without changing the output. In simple cases like this, you can use .eval and
.asg interchangeably. However, you must use .eval if you want to calculate a
value from an expression. While .asg only assigns a character string to a
substitution symbol, the .eval directive evaluates an expression and assigns
the character string equivalent to a substitution symbol.
5-8
Macro Parameters/Substitution Symbols
In the function definitions shown in Table 5-1, a and b are parameters that rep-
resent substitution symbols or character string constants. The term string re-
fers to the string value of the parameter. The symbol ch represents a character
constant.
5-10
Macro Parameters/Substitution Symbols
:symbol:
You can use the forced substitution operator only inside macros, and you
cannot nest a forced substitution operator within another forced substitution
operator.
force .macro x
.loop 8
AUX:x: .set x
.eval x+1,x
.endloop
.endm
force 0
The force macro would generate the following source code:
AUX0 .set 0
AUX1 .set 1
.
.
.
AUX7 .set 7
Example 5-8 and Example 5-9 show built-in substitution symbol functions
used with subscripted substitution symbols.
5-12
Macro Parameters/Substitution Symbols
.asg 0,pos
.asg ”ar1 ar2 ar3 ar4”,regs
substr 1,”ar2”,regs,pos
.data
.word pos
simple simple.asm
add3 add3.asm
You can access the macro library by using the .mlib assembler directive (de-
scribed on page 4-79). The syntax is:
When the assembler encounters the .mlib directive, it opens the library and
creates a table of the library’s contents. The assembler enters the names of
the individual members within the library into the opcode tables as library
entries; this redefines any existing opcodes or macros that have the same
name. If one of these macros is called, the assembler extracts the entry from
the library and loads it into the macro table.
The assembler expands the library entry in the same way it expands other
macros. You can control the listing of library entry expansions with the .mlist
directive. For more information about the .mlist directive, see Section 5.8,
Formatting the Output Listing, on page 5-22. Only macros that are actually
called from the library are extracted, and they are extracted only once.
You can use the archiver to create a macro library by simply including the
desired files in an archive. A macro library is no different from any other
archive, except that the assembler expects the macro library to contain macro
definitions. The assembler expects only macro definitions in a macro library;
putting object code or miscellaneous source files into the library may produce
undesirable results.
5-14
Using Conditional Assembly in Macros
The .elseif and .else directives are optional in conditional assembly. The
.elseif directive can be used more than once within a conditional assembly
code block. When .elseif and .else are omitted, and when the .if expression is
false (0), the assembler continues to the code following the .endif directive. For
more information on the .if/ .elseif/.else/.endif directives, see page 4-65.
The .loop directive’s optional expression evaluates to the loop count (the
number of loops to be performed). If the expression is omitted, the loop count
defaults to 1024 unless the assembler encounters a .break directive with an
expression that is true (nonzero). For more information on the .loop/
.break/.endloop directives, see page 4-77.
The .break directive and its expression are optional. If the expression
evaluates to false, the loop continues. The assembler breaks the loop when
the .break expression evaluates to true or when the .break expression is
omitted. When the loop is broken, the assembler continues with the code after
the .endloop directive.
Example 5-10, Example 5-11, and Example 5-12 show the .loop/.break/
.endloop directives, properly nested conditional assembly directives, and
built-in substitution symbol functions used in a conditional assembly code
block.
.asg 1,x
.loop
.eval x+1,x
.endloop
.asg 1,x
.loop
.eval x+1,x
.endloop
.ref OPZ
.fcnolist
*
*Double Add or Subtract
*
DBL .macro ABC, ADDR, src ; add or subtract double
.if $symcmp(ABC,”+”) == 0
dadd ADDR, src ; add double
.elseif $symcmp(ABC,”-”) == 0
dsub ADDR, src ; subtract double
.else
.emsg ”Incorrect Operator Parameter”
.endif
.endm
*Macro Call
DBL -, OPZ, A
For more information about conditional assembly directives, see Section 4.8,
Conditional Assembly Directives, on page 4-24.
5-16
Using Labels in Macros
The maximum label length is shortened to allow for the unique suffix. If the
macro is expanded fewer than 10 times, the maximum label length is 126
characters. If the macro is expanded from 10 to 99 times, the maximum label
length is 125. The label with its unique suffix is shown in the cross-listing file.
label?
1 ; define macro
2 MIN .macro AVAR, BVAR ; find minimum
3
4 LD AVAR, A
5 SUB #BVAR, A
6 BC M1?, ALT
7 LD #BVAR, A
8 B M2?
9 M1? LD AVAR, A
10 M2?
11 .endm
12
13 ; call macro
14 000000 MIN 50, 100
1
1 000000 1032 LD 50, A
1 000001 F010 SUB #100, A
000002 0064
1 000003 F843 BC M1?, ALT
000004 0008’
1 000005 E864 LD #100, A
1 000006 F073 B M2?
000007 0009’
1 000008 1032 M1? LD 50, A
1 000009 M2?
5-18
Using Labels in Macros
1 ; define macro
2 MIN .macro AVAR, BVAR ; find minimum
3
4 A = @AVAR
5 A = A - #BVAR
6 if (ALT) goto M1?
7 A = #BVAR
8 goto M2?
9 M1? A = @AVAR
10 M2?
11 .endm
12
13 ; call macro
14 000000 MIN 50, 100
1
1 000000 1032 A = @50
1 000001 F010 A = A - #100
000002 0064
1 000003 F843 if (ALT) goto M1?
000004 0008’
1 000005 E864 A = #100
1 000006 F073 goto M2?
000007 0009’
1 000008 1032 M1? A = @50
1 000009 M2?
Macro comments are comments that appear in the definition of the macro but
do not show up in the expansion of the macro. An exclamation point in column
1 identifies a macro comment. If you want your comments to appear in the
macro expansion, precede your comment with an asterisk or semicolon.
5-20
Producing Messages in Macros
.drlist causes the assembler to print to the listing file all directive
lines.
.drnolist suppresses the printing of the following directives in the list-
ing file: .asg, .eval, .var, .sslist, .mlist, .fclist, .ssnolist,
.mnolist, .fcnolist, .emsg, .wmsg, .mmsg, .length, .width, and
.break.
For directive listing, .drlist is the default.
5-22
Using Recursive and Nested Macros
When you create recursive or nested macros, you should pay close attention
to the arguments that you pass to macro parameters, because the assembler
uses dynamic scoping for parameters. This means that the called macro uses
the environment of the macro from which it was called.
Example 5-15 shows nested macros. Note that the y in the in_block macro
hides the y in the out_block macro. The x and z from the out_block macro,
however, are accessible to the in_block macro.
Example 5-16 shows recursive macros. The fact macro produces assembly
code necessary to calculate the factorial of n where n is an immediate value.
The result is placed in data memory address loc. The fact macro accomplishes
this by calling fact1, which calls itself recursively.
ST #1, loc
.else
ST #N, loc ; n >= 2 so, store n at loc
; decrement n, and do the
.eval N - 1, N ; factorial of n - 1
fact1 ; call fact with current
; environment
.endif
.endm
fact1 .macro
.if N > 1
LD loc, T ; multiply present factorial
MPY #N, A ; by present position
STL A, loc ; save result
.eval N - 1, N ; decrement position
fact1 ; recursive call
.endif
.endm
5-24
Using Recursive and Nested Macros
@loc = #1
.else
@loc = #N ; n >= 2 so, store n at loc
; decrement n, and do the
.eval N - 1, N ; factorial of n - 1
fact1 ; call fact1 with current
; environment
.endif
.endm
fact1 .macro
.if N > 1
T = @loc ; multiply present factorial
A = T * #N ; by present position
@loc = A ; save result
.eval N - 1, N ; decrement position
fact1 ; recursive call
.endif
.endm
.mexit Go to .endm.
.eval well-defined expression, substitution symbol Perform arithmetic on numeric substitution symbols.
5-26
Macro Directives Summary
Linker Description
Topic Page
6-1
Linker Overview
6-2
Linker Development Flow
C
source
files
Macro
source
files
C compiler
Translator
Archiver utility
Assembler
source
Macro
library Assembler
source
Assembler
Library-build
COFF utility
object
Archiver
files
Runtime-
support
Library of library
object
files Linker
Debugging
tools
Executable
COFF
file
Hex conversion
utility
EPROM Cross-reference
programmer Absolute lister lister C54x
- Specify options and filenames on the command line. This example links
two files, file1.obj and file2.obj, and creates an output module named
link.out.
lnk500 file1.obj file2.obj -o link.out
- Enter the lnk500 command with no filenames and no options; the linker
prompts for them:
Command files :
Object files [.obj] :
Output file [a.out] :
Options :
J For command files, enter one or more command filenames.
J For object files, enter one or more object filenames. The default exten-
sion is .obj. Separate the filenames with spaces or commas; if the last
character is a comma, the linker prompts for an additional line of object
filenames.
J The output file is the name of the linker output module. This overrides
any -o options entered with any of the other prompts. If there are no
- o options and you do not answer this prompt, the linker creates an
object file with a default filename of a.out.
J The options prompt is for additional options, although you can also
enter them in a command file. Enter them with hyphens, just as you
would on the command line.
6-4
Invoking the Linker
- Put filenames and options in a linker command file. For example, assume
that the file linker.cmd contains the following lines:
-o link.out
file1.obj
file2.obj
Now you can invoke the linker from the command line; specify the
command filename as an input file:
lnk500 linker.cmd
When you use a command file, you can also specify other options and files
on the command line. For example, you could enter:
lnk500 -m link.map linker.cmd file3.obj
The linker reads and processes a command file as soon as it encounters
the filename on the command line, so it links the files in this order: file1.obj,
file2.obj, and file3.obj. This example creates an output file called link.out
and a map file called link.map.
6-6
Linker Options
When you use the -a option without the -r option, the linker produces an
absolute, executable output module. Absolute files retain no relocation
information. Executable files contain the following:
J Special symbols defined by the linker (subsection 6.15.4, Symbols
Defined by the Linker, on page 6-73 describes these symbols)
J An optional header that describes information such as the program
entry point
J No unresolved references
The following example links file1.obj and file2.obj and creates an absolute
output module called a.out:
lnk500 -a file1.obj file2.obj
6-8
Linker Options
When you use the -r option without the -a option, the linker retains
relocation entries in the output module. If the output module will be
relocated (at load time) or relinked (by another linker execution), use -r to
retain the relocation entries.
The linker produces a file that is not executable when you use the -r option
without -a. A file that is not executable does not contain special linker
symbols or an optional header. The file may contain unresolved refer-
ences, but these references do not prevent creation of an output module.
The following example links file1.obj and file2.obj and creates a relocat-
able output module called a.out:
-[ f1.c ]-
#include ”header.h”
...
-[ f2.c ]-
#include ”header.h”
...
When these files are compiled for debugging, both f1.obj and f2.obj will have
symbolic debugging entries to describe type XYZ. For the final output file, only
one set of these entries is necessary. The linker eliminates the duplicate
entries automatically.
Use the -b option if you want the linker to keep such duplicate entries. This
effect is offset by the effort that the loader has to go through downstream to
load and manage duplicate debug information.
For more information about linking C/C++ code, see Section 6.18, Linking
C/C++ Code, on page 6-80 and subsection 6.18.5, The -c and -cr Linker
Options, on page 6-84.
6-10
Linker Options
The linker can assign one of four possible values to the entry point. These
values are listed below in the order in which the linker tries to use them. If you
use one of the first three values, it must be an external symbol in the symbol
table.
-e global_symbol
Where global_symbol defines the entry point and must appear as an
external symbol in one of the input files.
- The value of symbol _c_int00 (if present). _c_int00 must be the entry point
if you are linking code produced by the C/C++ compiler.
This example links file1.obj and file2.obj. The symbol begin is the entry point;
begin must be defined and externally visible (accessible) in file1 or file2.
lnk500 -e begin file1.obj file2.obj
6-12
Linker Options
For more information about linking C code, see Section 6.18, Linking C Code,
on page 6-80.
6.4.9 Alter the Library Search Algorithm (-l Option, -i Option, and
C54X_C_DIR/C_DIR Environment Variables)
Usually, when you want to specify a library as linker input, you simply enter the
library name as you would any other input filename; the linker looks for the
library in the current directory. For example, suppose the current directory
contains the library object.lib. Assume that this library defines symbols that are
referenced in the file file1.obj. This is how you link the files:
lnk500 file1.obj object.lib
If you want to use a library that is not in the current directory, use the -l
(lowercase L) linker option. The syntax for this option is:
-l filename
The filename is the name of an archive library; the space between -l and the
filename is optional.
The -l option is not required when one or more members of an object library
are specified for input to an output section. For more information, see section
6.9.4, Allocating an Archive Member to an Output Section.
You can augment the linker’s directory search algorithm by using the -i linker
option or the C_DIR or C54X_C_DIR environment variables. The linker
searches for object libraries in the following order:
3) If C_DIR and C54X_C_DIR are not set, it searches directories named with
the assembler’s environment variables, C54X_A_DIR and A_DIR.
The -i option names an alternate directory that contains object libraries. The
syntax for this option is:
-i dir
The dir names a directory that contains object libraries; the space between -i
and the directory name is optional.
When the linker is searching for object libraries named with the -l option, it
searches through directories named with -i first. Each -i option specifies only
one directory, but you can use several -i options per invocation. When you use
the -i option to name an alternate directory, it must precede the -l option on
the command line or in a command file.
For example, assume that there are two archive libraries called r.lib and
lib2.lib. The table below shows the directories that r.lib and lib2.lib reside in,
how to set environment variable, and how to use both libraries during a link.
Select the row for your operating system:
UNIX /ld and /ld2 lnk500 f1.obj f2.obj -i/ld -i/ld2 -lr.lib -llib2.lib
6-14
Linker Options
An environment variable is a system symbol that you define and assign a string
to. The linker uses environment variables named C_DIR and C54X_C_DIR to
name alternate directories that contain object libraries. The commands for
assigning the environment variable are:
The pathnames are directories that contain object libraries. Use the -l option
on the command line or in a command file to tell the linker which libraries to
search for.
In the example below, assume that two archive libraries called r.lib and lib2.lib
reside in ld and ld2 directories. The table below shows the directories that r.lib
and lib2.lib reside in, how to set the environment variable, and how to use both
libraries during a link. Select the row for your operating system:
Note that the environment variable remains set until you reboot the system or
reset the variable by entering:
-m filename
Note that symbols in a data section are in words, and symbols in a code section
are in bytes.
The map file contains the name of the output module and the entry point; it may
also contain up to three tables:
6-16
Linker Options
- A table showing the linked addresses of each output section and the input
sections that make up the output sections
- A table showing each external symbol and its address. This table has two
columns: the left column contains the symbols sorted by name, and the
right column contains the symbols sorted by address
This example links file1.obj and file2.obj and creates a map file called file.map:
lnk500 file1.obj file2.obj -m file.map
-o filename
This example links file1.obj and file2.obj and creates an output module named
run.out:
lnk500 -o run.out file1.obj file2.obj
This example links file1.obj and file2.obj and creates an output module,
stripped of line numbers and symbol table information, named nosym.out:
lnk500 -o nosym.out -s file1.obj file2.obj
Using the -s option limits later use of a symbolic debugger and may prevent
a file from being relinked.
If you specified a different stack size in an input section, the input section stack
size is ignored. Any symbols defined in the input section remain valid; only the
stack size will be different.
When the linker defines the .stack section, it also defines a global symbol,
__STACK_SIZE, and assigns it a value equal to the size of the section. The
default stack size is 1K words.
When the linker defines the .sysstack section, it also defines a global symbol,
__SYSSTACK_SIZE, and assigns it a value equal to the size of the section
(in bytes). The default secondary stack size is 1000 bytes.
6-18
Linker Options
For example, suppose a library named rts.lib contains a member that defines
the symbol symtab; none of the object files being linked reference symtab.
However, suppose you plan to relink the output module, and you would like to
include the library member that defines symtab in this link. Using the -u option
as shown below forces the linker to search rts.lib for the member that defines
symtab and to link in the member.
lnk500 -u symtab file1.obj file2.obj rts.lib
If you do not use -u, this member is not included because there is no explicit
reference to it in file1.obj or file2.obj.
For more information about the SECTIONS directive, see Section 6.9, The
SECTIONS Directive, on page 6-35. For more information about the default
actions of the linker, see Section 6.13, Default Allocation Algorithm, on page
6-66.
6-20
Linker Options
The linker normally reads input files, including archive libraries, only once
when they are encountered on the command line or in the command file. When
an archive is read, any members that resolve references to undefined symbols
are included in the link. If an input file later references a symbol defined in a
previously read archive library, the reference will not be resolved.
With the -x option, you can force the linker to reread all libraries. The linker
rereads libraries until no more references can be resolved. Linking using the
-x option may be slower, so you should use it only as needed. For example,
if a.lib contains a reference to a symbol defined in b.lib, and b.lib contains a
reference to a symbol defined in a.lib, you can resolve the mutual
dependencies by listing one of the libraries twice, as in:
lnk500 -la.lib -lb.lib -la.lib
or you can force the linker to do it for you:
lnk500 -x -la.lib -lb.lib
The option -priority is used to provide an alternate search mechanism for li-
braries. -priority causes each unresolved reference to be satisfied by the first
library that contains a definition for that symbol.
For example:
objfile references A
lib1 defines B
lib2 defines A, B; obj defining A references B
-priority and linking your new library “in front of” rts500.lib guarantees that all
references to malloc and free resolve to the new library.
This option is intended to support linking programs with DSP/BIOS where situ-
ations like the one illustrated above occur.
6-22
Byte/Word Addressing
In the case of program labels, the unchanged byte addresses will be encoded
in the executable output and during execution sent over the program address
bus. In the case of data labels, the byte addresses will be divided by 2 in the
linker (converting them to word addresses) prior to being encoded in the
executable output and sent over the data address bus.
The .map file created by the linker shows code addresses and sizes in bytes,
and data addresses and sizes in words.
Linker command files are ASCII files that contain one or more of the following:
- Linker options, which can be used in the command file in the same manner
that they are used on the command line.
To invoke the linker with a command file, enter the lnk500 command and follow
it with the name of the command file:
lnk500 command_filename
The linker processes input files in the order that it encounters them. If the linker
recognizes a file as an object file, it includes that file in the link. Otherwise, it
assumes that a file is a command file and begins reading and processing com-
mands from it. Command filenames are case sensitive, regardless of the sys-
tem used.
6-24
Linker Command Files
The sample file in Example 6-1 contains only filenames and options. You can
place comments in a command file by delimiting them with /* and */. To invoke
the linker with this command file, enter:
lnk500 link.cmd
You can place other parameters on the command line when you use a
command file:
lnk500 -r link.cmd c.obj d.obj
You can specify multiple command files. If, for example, you have a file called
names.lst that contains filenames and another file called dir.cmd that contains
linker directives, you could enter:
lnk500 names.lst dir.cmd
One command file can call another command file; this type of nesting is limited
to 16 levels.
Blanks and blank lines are insignificant in a command file except as delimiters.
This also applies to the format of linker directives in a command file.
Example 6-2 shows a sample command file that contains linker directives.
(Linker directive formats are discussed in later sections.)
6-26
Linker Command Files
Examples:
Decimal Octal Hexadecimal
Assembler Format: 32 40q 20h
C Format: 32 040 0x20
Using object libraries can reduce link time and the size of the executable
module. Normally, if an object file that contains a function is specified at link
time, it is linked whether it is used or not; however, if that same function is
placed in an archive library, it is included only if it is referenced.
The order in which libraries are specified is important because the linker
includes only those members that resolve symbols that are undefined when
the library is searched. The same library can be specified as often as neces-
sary; it is searched each time it is included. Alternatively, the -x option can be
used. A library has a table that lists all external symbols defined in the library;
the linker searches through the table until it determines that it cannot use the
library to resolve any more references.
The following examples link several files and libraries. Assume that:
- Input files f1.obj and f2.obj both reference an external function named
clrscr
For example, if you enter the following, the references are resolved as shown:
lnk500 f1.obj liba.lib f2.obj libc.lib
- Member 1 of liba.lib satisfies both references to clrscr because the library
is searched and clrscr is defined before f2.obj references it.
6-28
Object Libraries
If, however, you enter the following, all the references to clrscr are satisfied by
member 1 of libc.lib:
lnk500 f1.obj f2.obj libc.lib liba.lib
If none of the linked files reference symbols defined in a library, you can use
the -u option to force the linker to include a library member. The next example
creates an undefined symbol rout1 in the linker’s global symbol table:
lnk500 -u rout1 libc.lib
If any member of libc.lib define rout1, the linker includes those members.
The linker allows you to allocate individual members of an archive library into
a specific output section. For more information, see Section 6.9.4, Allocating
an Archive Member to an Output Section.
Section 6.4.9, Alter the Library Search Algorithm (-i dir Option/C_DIR), on
page 6-13, describes methods for specifying directories that contain object
libraries.
Refer to Section 2.4, How the Linker Handles Sections, on page 2-13 for
details on how the linker handles sections. Refer to Section 2.5, Relocation,
on page 2-16 for information on the relocation of sections.
C54x devices have separate memory spaces that occupy the same address
ranges. In the default model, one space is dedicated to program areas, while
a second is dedicated to data (the number of separate address spaces
depends on the customized configuration of your chip. See the TMS320C54x
DSP Reference Set for more information).
The linker allows you to configure these address spaces separately by using
the MEMORY directive’s PAGE option. In the default model, PAGE 0 refers to
program memory, and PAGE 1 refers to peripheral (iospace) memory. The
linker treats these two pages as completely separate memory spaces. The
C54x supports as many as 255 PAGES, but the number available to you
depends on the configuration you have chosen.
6-30
The MEMORY Directive
By default, the linker uses a single address space on PAGE 0. However, the
linker allows you to configure separate address spaces by using the MEMORY
directive’s PAGE option. The PAGE option causes the linker to treat the
specified pages as completely separate memory spaces. C54x supports as
many as 255 PAGES, but the number available to you depends on the
configuration you have chosen.
When you use the MEMORY directive, be sure to identify all the memory
ranges that are available for object code. Memory defined by the MEMORY
directive is configured memory; any memory that you do not explicitly account
for with the MEMORY directive is unconfigured memory. The linker does not
place any part of a program into unconfigured memory. You can represent non-
existent memory spaces by simply not including an address range in a
MEMORY directive statement.
/**************************************************/
/* Sample command file with MEMORY directive */
/**************************************************/
file1.obj file2.obj /* Input files */
-o prog.out /* Options */
MEMORY
MEMORY
directive
{
PAGE 0: ROM: origin = C00h, length = 1000h
PAGE
options PAGE 1: SCRATCH: origin = 60h, length = 20h
ONCHIP: origin = 80h, length = 1000h
}
MEMORY
{
PAGE 0 : name 1 [(attr)] : origin = constant , length = constant;
PAGE n : name n [(attr)] : origin = constant , length = constant;
}
6-32
The MEMORY Directive
The following example specifies a memory range with the R and W attributes
and a fill constant of 0FFFFh:
MEMORY
{
RFILE (RW) : o = 02h, l = 0FEh, f = 0FFFFh
}
You normally use the MEMORY directive in conjunction with the SECTIONS
directive to control allocation of output sections. After you use the MEMORY
directive to specify the target system’s memory model, you can use the
SECTIONS directive to allocate output sections into specific named memory
ranges or into memory that has specific attributes. For example, you could
allocate the .text and .data sections into the area named ROM and allocate the
.bss section into the area named ONCHIP.
ÉÉÉÉ
Data Memory Program Memory
ÉÉÉÉ
00000h 00000h
ÉÉÉÉ
0005Fh
ÉÉÉÉ
ÉÉÉÉ ÉÉÉÉ
00060h SCRATCH
0007Fh
ÉÉÉÉ
00080h
ONCHIP on-chip
ÉÉÉÉ
ÉÉÉÉ
RAM
ÉÉÉÉ
0107Fh
ÉÉÉÉ
ÉÉÉÉ ÉÉÉÉ
01080h
ÉÉÉÉ 00C00h
ÉÉÉÉ ÉÉÉÉ
01C00h
ÉÉÉÉ ÉÉÉÉ
0FFFFh
0FFFFh
6-34
The SECTIONS Directive
- Specifies where output sections are placed in memory (in relation to each
other and to the entire memory space)
Refer to Section 2.4, How the Linker Handles Sections, on page 2-13 for
details on how the linker handles sections. Refer to Section 2.5, Relocation,
on page 2-16 for information on the relocation of sections. Refer to subsection
2.3.4, Subsections, on page 2-9 for information on defining subsections;
subsections allow you to manipulate sections with greater precision.
SECTIONS
{
name : [property, property, property,...]
name : [property, property, property,...]
name : [property, property, property,...]
}
- Input sections, which define the input sections that constitute the output
section
Syntax: { input_sections }
- Fill value, which defines the value used to fill uninitialized holes
Syntax: fill = value or
name: ... { ... } = value
For more information on creating and filling holes, see Section 6.16,
Creating and Filling Holes, on page 6-74.
6-36
The SECTIONS Directive
/**************************************************/
/* Sample command file with SECTIONS directive */
/**************************************************/
file1.obj file2.obj /* Input files */
-o prog.out /* Options */
SECTIONS
directive
SECTIONS
{
.text: load = ROM, run = 800h
.const: load = ROM
.bss: load = RAM
.vectors: load = FF80h
{
section t1.obj(.intvec1)
specifications t2.obj(.intvec2)
endvec = .;
}
.data: align = 16
}
Figure 6-3 shows the five output sections defined by the sections directive in
Example 6-4: .vectors, .text, .const, .bss, and .data.
ÉÉÉÉÉÉ
and align it to a 16-word boundary.
ROM
The .text section combines the .text sections from
.text - allocated in ROM
file1.obj and file2.obj. The linker combines all sec-
tions named .text into this section. The application
must relocate the section to run at 0800h.
.const - allocated in ROM
The .const section combines the .const sections
from file1.obj and file2.obj.
FF80h .vectors - bound at 0FF80h The .vectors section is composed of the .intvec1
section from t1.obj and the .intvec2 section from
t2.obj.
6.9.3 Allocation
The linker assigns each output section two locations in target memory: the
location where the section will be loaded and the location where it will be run.
Usually, these are the same, and you can think of each section as having only
a single address. In any case, the process of locating the output section in the
target’s memory and assigning its address(es) is called allocation. For more
information about using separate load and run allocation, see Section 6.10,
Specifying a Section’s Run-Time Address, on page 6-48.
If you do not tell the linker how a section is to be allocated, it uses a default
algorithm to allocate the section. Generally, the linker puts sections wherever
they fit into configured memory. You can override this default allocation for a
section by defining it within a SECTIONS directive and providing instructions
on how to allocate it.
6-38
The SECTIONS Directive
Blocking uses the block keyword to specify that the section must fit
between two address boundaries: if the section is too big, it
will start on an address boundary.
.text: block(0x80)
Page specifies the memory page to be used (see Section 6.12,
Overlay Pages, on page 6-61).
.text: PAGE 0
For the load (usually the only) allocation, you may simply use a greater-than
sign and omit the load keyword:
.text: > ROM .text: {...} > ROM
.text: > 0x1000
If more than one parameter is used, you can string them together as follows:
.text: > ROM align 16 PAGE 2
6.9.3.1 Binding
You can supply a specific starting address for an output section by following
the section name with an address:
.text: 0x1000
This example specifies that the .text section must begin at word location
1000h. The binding address must be a 16-bit constant.
You can allocate a section into a memory range that is defined by the
MEMORY directive. This example names ranges and links sections into them:
MEMORY
{
ROM (RIX) : origin = 0C00h, length = 1000h
RAM (RWIX) : origin = 0080h, length = 1000h
}
SECTIONS
{
.text : > ROM
.data ALIGN(128) : > RAM
.bss : > RAM
In this example, the linker places .text into the area called ROM. The .data and
.bss output sections are allocated into RAM. You can align a section within a
named memory range; the .data section is aligned on a 128-word boundary
within the RAM range.
Similarly, you can link a section into an area of memory that has particular
attributes. To do this, specify a set of attributes (enclosed in parentheses)
instead of a memory name. Using the same MEMORY directive declaration,
you can specify:
SECTIONS
{
.text: > (X) /* .text --> executable memory */
.data: > (RI) /* .data --> read or init memory */
.bss : > (RW) /* .bss --> read or write memory */
}
In this example, the .text output section can be linked into either the ROM or
RAM area because both areas have the X attribute. The .data section can also
go into either ROM or RAM because both areas have the R and I attributes.
The .bss output section, however, must go into the RAM area because only
RAM is declared with the W attribute.
6-40
The SECTIONS Directive
You can tell the linker to place an output section at an address that falls on an
n-word boundary, where n is a power of 2. For example:
.text: load = align(128)
allocates .bss so that the section either is contained in a single 128-word page
or begins on a page.
You can use alignment or blocking alone or in conjunction with a memory area,
but alignment and blocking cannot be used together.
An input section specification identifies the sections from input files that are
combined to form an output section. The size of an output section is the sum
of the sizes of the input sections that comprise it. The linker combines input
sections by concatenating them in the order in which they are specified, unless
alignment or blocking is specified for any of the input sections.
When the linker encounters a simple object file reference (with no path specifi-
cation) in the linker command file, it will try to match the file to any previously-
specified input files. If the reference does not match one of the input files, the
linker will look for the object file in the current directory and load it if it is found.
To disable this functionality, include a path specification with your object file ref-
erence in the linker command file.
If alignment or blocking is specified for any input section, the input sections
within an output section are ordered as follows:
Example 6-5 shows the most common type of section specification; note that
no input sections are listed.
SECTIONS
{
.text:
.data:
.bss:
}
In Example 6-5 the linker takes all the .text sections from the input files and
combines them into the .text output section. The linker concatenates the .text
input sections in the order that it encounters them in the input files. The linker
performs similar operations with the .data and .bss sections. You can use this
type of specification for any output section.
You can explicitly specify the input sections that form an output section. Each
input section is identified by its filename and section name:
SECTIONS
{
.text : /* Build .text output section */
{
f1.obj(.text) /* Link .text section from f1.obj */
f2.obj(sec1) /* Link sec1 section from f2.obj */
f3.obj /* Link ALL sections from f3.obj */
f4.obj(.text,sec2) /* Link .text and sec2 from f4.obj */
}
}
It is not necessary for input sections to have the same name as each other or
as the output section they become part of. If a file is listed with no sections, all
of its sections are included in the output section. If any additional input sections
have the same name as an output section, but are not explicitly specified by
the SECTIONS directive, they are automatically linked in at the end of the
output section. For example, if the linker found more .text sections in the
preceding example, and these .text sections were not specified anywhere in
the SECTIONS directive, the linker would concatenate these extra sections
after f4.obj(sec2).
The specifications in Example 6-5 are actually a shorthand method for the
following:
SECTIONS
{
.text: { *(.text) }
.data: { *(.data) }
.bss: { *(.bss) }
}
6-42
The SECTIONS Directive
The specification *(.text) means the unallocated .text sections from all the
input files. This format is useful when:
- You want the output section to contain all input sections that have a
specified name, but the output section name is different than the input
sections’ name.
- You want the linker to allocate the input sections before it processes addi-
tional input sections or commands within the braces.
SECTIONS
{
.output_sec
{
[-l]lib_name<obj1 [obj2...objn]> (.sec_name)
}
}
In this syntax, the lib_name is the archive library. The -l option, which normally
implies a library path search be made for the named file, is optional in this syn-
tax since the < > mechanism requires that the file from which the members are
selected must be an archive. In this case, the linker always utilizes a library
path search to find the archive. However, if the specified lib_name contains
any path information, then a library path search is not performed when looking
for the library file.
For more information on the -l option, see section 6.4.9, Alter the Library
Search Algorithm, on page 6-13.
Brackets (<>) are used to specify the archive member(s). The brackets may
contain one or more object files, separated by a space. The sec_name is the
archive section to be allocated.
For example:
SECTIONS
{
.boot > BOOT1
{
/* This is the new support */
-l rts.lib<boot.obj> (.text)
rts.lib< exit.obj strcpy.obj> (.text)
}
.rts > BOOT2
{
-l rts.lib (.text)
}
.text > RAM
{
* (.text)
}
}
In this example, boot.obj, exit.obj, and strcpy.obj are extracted from the run-
time support library and placed in the “.boot” output section.
The remainder of the runtime support library object that is referenced is allo-
cated to the “.rts” output section. An archive member, or list of members, can
now be specified via < >’s after the library name.
All other unallocated .text sections are placed in the .text section.
The linker allows you to specify an explicit list of memory ranges into which an
output section can be allocated. Consider the following example:
6-44
The SECTIONS Directive
MEMORY
{
P_MEM1 : origin = 02000h, length = 01000h
P_MEM2 : origin = 04000h, length = 01000h
P_MEM3 : origin = 06000h, length = 01000h
P_MEM4 : origin = 08000h, length = 01000h
}
SECTIONS
{
.text : { } > P_MEM1 | P_MEM2 | P_MEM4
}
The “|” operator is used to specify the multiple memory ranges. The .text output
section will be allocated as a whole into the first memory range in which it fits.
The memory ranges are accessed in the order specified. In this example, the
linker will first try to allocate the section in P_MEM1. If that attempt fails, the
linker will try to place the section into P_MEM2, and so on. If the output section
is not successfully allocated in any of the named memory ranges, the linker
issues an error message.
With this type of SECTIONS directive specification, the linker can seamlessly
handle an output section that grows beyond the available space of the memory
range in which it is originally allocated. Instead of modifying the linker com-
mand file, you can let the linker move the section into one of the other areas.
SECTIONS
{
.text: { *(.text) } >> P_MEM1 | P_MEM2 | P_MEM3 | P_MEM4
}
In this example, the >> operator indicates that the .text output section can be
split among any of the listed memory areas. If the .text section grows beyond
the available memory in P_MEM1, it is split on an input section boundary, and
The “|” operator is used to specify the list of multiple memory ranges.
You can also use the >> operator to indicate that an output section can be split
within a single memory range. This functionality is useful when several output
sections must be allocated into the same memory range, but the restrictions
of one output section cause the memory range to be partitioned. Consider the
following example:
MEMORY
{
RAM : origin = 01000h, length = 08000h
}
SECTIONS
{
.special: { f1.obj(.text) } = 04000h
.text: { *(.text) } >> RAM
}
The .special output section is allocated near the middle of the RAM memory
range. This leaves two unused areas in RAM: from 01000h to 04000h, and
from the end of f1.obj(.text) to 08000h. The specification for the .text section
allows the linker to split the .text section around the .special section and use
the available space in RAM on either side of .special.
The >> operator can also be used to split an output section among all memory
ranges that match a specified attribute combination. For example:
MEMORY
{
P_MEM1 (RWX) : origin = 01000h, length = 02000h
P_MEM2 (RWI) : origin = 04000h, length = 01000h
}
SECTIONS
{
.text: { *(.text) } >> (RW)
}
The linker will attempt to allocate all or part of the output section into any
memory range whose attributes match the attributes specified in the
SECTIONS directive.
6-46
The SECTIONS Directive
- .pinit, which contains the list of global constructors for C++ programs
- An output section with separate load and run allocations. The code that
copies the output section from its load-time allocation to its run-time loca-
tion cannot accommodate a split in the output section.
- GROUPs and UNIONs, which are used to allocate address and dimension
operators.
If you use the >> operator on any of these sections, the linker issues a warning
and ignores the operator.
At times, you may want to load code into one area of memory and run it in
another. For example, you may have performance-critical code in a ROM-
based system. The code must be loaded into ROM, but it would run faster in
RAM.
The linker provides a simple way to accomplish this. You can use the
SECTIONS directive to direct the linker to allocate a section twice: once to set
its load address and again to set its run address. For example:
Use the load keyword for the load address and the run keyword for the run
address.
The load address determines where a loader will place the raw data for the
section. All references to the section (such as labels in it) refer to its run
address. The application must copy the section from its load address to its run
address; this does not happen automatically when you specify a separate run
address.
If you provide only one allocation (either load or run) for a section, the section
is allocated only once and will load and run at the same address. If you provide
both allocations, the section is allocated as if it were two sections of the same
size. This means that both allocations occupy space in the memory map and
cannot overlay each other or other sections. (The UNION directive provides
a way to overlay sections; see subsection 6.11.1, Overlaying Sections With the
UNION Statement, on page 6-56.)
If either the load or run address has additional parameters, such as alignment
or blocking, list them after the appropriate keyword. Everything related to
allocation after the keyword load affects the load address until the keyword run
is seen, after which, everything affects the run address. The load and run
allocations are completely independent, so any qualification of one (such as
alignment) has no effect on the other. You may also specify run first, then load.
Use parentheses to improve readability.
6-48
Specifying a Section’s Load-Time and Run-Time Addresses
A warning is issued, load is ignored, and space is allocated in RAM. All of the
following examples have the same effect. The .bss section is allocated in RAM.
.bss: load = RAM
.bss: run = RAM
.bss: > RAM
;-------------------------------------------------------
; define a section to be copied from ROM to RAM
;-------------------------------------------------------
.sect ”.fir”
.label fir_src ; load address of section
fir: ; run address of section
<code here> ; code for the section
.label fir_end ; load address of section end
;-------------------------------------------------------
; copy .fir section from ROM into RAM
;-------------------------------------------------------
.text
STM fir_src, AR1 ; get load address
RPT #(fir_end - fir_src - 1)
MVDP *AR1+, fir ; copy address to program memory
;-------------------------------------------------------
; jump to section, now in RAM
;-------------------------------------------------------
CALL fir
/**************************************************/
/* PARTIAL LINKER COMMAND FILE FOR FIR EXAMPLE */
/**************************************************/
MEMORY
{
PAGE 0 : ONCHIP : origin = 0800h, length = 02400h
PAGE 0 : PROG : origin = 02C00h, length = 0D200h
PAGE 1 : DATA : origin = 0800h, length = 0F800h
}
SECTIONS
{
.text: load = PROG PAGE 0
.fir: load = DATA PAGE 1, run ONCHIP PAGE 0
}
6-50
Specifying a Section’s Load-Time and Run-Time Addresses
800h 800h
ONCHIP DATA
2C00h
PROG
.text
FE00h
The code generation tools currently support the ability to load program code
in one area of (slow) memory and run it in another (faster) area. This is done
by specifying separate load and run addresses for an output section or
GROUP in the linker command file, then executing a sequence of instructions
(the copying code) that moves the program code from its load area to its run
area before it is needed.
There are several responsibilities that you take on when setting up a system
with this feature. One of these responsibilities is to determine the size and run-
time address of the program code to be moved. The current mechanisms to
do this involve the use of .label directives in the copying code as shown in
Example 6-7.
; program code
.sect ”.fir”
.label fir_src ; load address of section
fir: ; run address of section
<.fir section program code>
.text
; copying code
MOV #fir_src, AR1
MOV #fir
RPT #(fir_end - fir_src - 1)
MOV *AR1+, *CDP+
CALL fir
This method of specifying the size and load address of the program code has
limitations. While it works fine for an individual input section that is contained
entirely within one source file, what if the program code section is spread over
several source files? What if you want to copy an entire output section from
load space to run space?
Suppose there is padding between s1.obj and s2.obj that is created as a result
of alignment. Then start_of_s2 is not really the start address of the .text section
6-52
Specifying a Section’s Load-Time and Run-Time Addresses
in s2.obj, but it is the address before the padding needed to align the .text sec-
tion in s2.obj. This is due to the linker’s interpretation of the dot operator as the
current PC. It is also due to the fact that the dot operator is evaluated indepen-
dently of the input sections around it.
Another potential problem in the above example is that end_of_s2 may not ac-
count for any padding that was required at the end of the output section. You
cannot reliably use end_of_s2 as the end address of the output section. One
way to get around this problem is to create a dummy section immediately after
the output section in question. For example:
GROUP
{
outsect:
{
start_of_outsect = .;
...
}
dummy: { size_of_outsect = . - start_of_outsect; }
}
Six new operators have been added to the linker command file syntax:
The new address and dimension operators can be associated with several dif-
ferent kinds of allocation units, including input items, output sections,
GROUPs, and UNIONs. The following sections provide some examples of
how the operators can be used in each case.
This can be rewritten using the START and END operators as follows:
outsect:
{
s1.obj(.text) { END(end_of_s1) }
s2.obj(.text) { START(start_of_s2), END(end_of_s2) }
}
The values of end_of_s1 and end_of_s2 will be the same as if you had used
the dot operator in the original example, but start_of_s2 would be defined after
any necessary padding that needs to be added between the two .text sections.
Remember that the dot operator would cause start_of_s2 to be defined before
any necessary padding is inserted between the two input sections.
The syntax for using these operators in association with input sections calls
for braces ’{’, ’}’ to enclose the operator list. The operators specified in the list
will be applied to the input item that occurs immediately before it.
In this case, the SIZE operator defines size_of_outsect to incorporate any pad-
ding that is required in the output section to conform to any alignment require-
ments that are imposed.
The syntax for specifying the operators with an output section do not require
braces to enclose the operator list. The operator list is simply included as part
of the allocation specification for an output section.
6.10.6.3 GROUPs
Here is another use of the START and SIZE operators in the context of a
GROUP specification:
6-54
Specifying a Section’s Load-Time and Run-Time Addresses
GROUP
{
outsect1: { ... }
outsect2: { ... }
} load = ROM, run = RAM, START(group_start), SIZE(group_size);
This can be useful if the whole GROUP is to be loaded in one location and run
in another. The copying code can use group_start and group_size as parame-
ters for where to copy from and how much is to be copied. This makes the use
of .label in the source code unnecessary.
6.10.6.4 UNIONs
Here union_ld_sz is going to be equal to the sum of the sizes of all output sec-
tions placed in the union. The union_run_sz value is equivalent to the largest
output section in the union. Both of these symbols incorporate any padding
due to blocking or alignment requirements.
In Example 6-8, the .bss sections from file1.obj and file2.obj are allocated at
the same address in RAM. In the memory map, the union occupies as much
space as its largest component. The components of a union remain
independent sections; they are simply allocated together as a unit.
SECTIONS
{
.text: load = ROM
UNION: run = RAM
{
.bss1: { file1.obj(.bss) }
.bss2: { file2.obj(.bss) }
}
.bss3: run = RAM { globals.obj(.bss) }
}
Allocation of a section as part of a union affects only its run address. Under no
circumstances can sections be overlaid for loading. If an initialized section is
a union member (an initialized section has raw data, such as .text), its load
allocation must be separately specified. For example:
6-56
Using UNION and GROUP Statements
Figure 6-5. Memory Allocation Shown in Example 6-8 and Example 6-9
Allocation for Example 6-8 Allocation for Example 6-9
RAM RAM
.bss2 Sections can run Copies at
.text 2 (run)
as a union. This is run time
.bss1 run-time allocation .text 1 (run)
only.
.bss3
ÉÉÉÉÉÉÉ ÉÉÉÉÉÉ
ÉÉÉÉÉÉÉ ÉÉÉÉÉÉ
ÉÉÉÉÉÉÉ
.text
ROM ÉÉÉÉÉÉ ROM
.text 1 (load)
Sections cannot
load as a union. .text 2 (load)
ÉÉÉÉÉÉÉ ÉÉÉÉÉÉ
ÉÉÉÉÉÉÉ ÉÉÉÉÉÉ
ÉÉÉÉÉÉÉ ÉÉÉÉÉÉ
Since the .text sections contain data, they cannot load as a union, although
they can be run as a union. Therefore, each requires its own load address. If
you fail to provide a load allocation for an initialized section within a union, the
linker issues a warning and allocates load space anywhere it fits in configured
memory.
Uninitialized sections are not loaded and do not require load addresses.
The UNION statement applies only to allocation of run addresses, so it is
redundant to specify a load address for the union itself. For purposes of
allocation, the union is treated as an uninitialized section: any one allocation
specified is considered a run address, and, if both are specified, the linker
issues a warning and ignores the load address.
The alignment and block attributes of a union are the maximum alignment and
block attributes of any of its members. Unions are always even aligned.
SECTIONS
{
.text /* Normal output section */
.bss /* Normal output section */
GROUP 1000h : /* Specify a group of sections */
{
.data /* First section in the group */
term_rec /* Allocated immediately after .data */
}
}
You can use binding, alignment, or named memory to allocate a GROUP in the
same manner as a single output section. In the preceding example, the
GROUP is bound to word address 1000h. This means that .data is allocated
at word 1000h, and term_rec follows it in memory.
The alignment and block attributes of a GROUP are the maximum alignment
and block attributes of any of its members. GROUPs are always even aligned.
6-58
Using UNION and GROUP Statements
Given the example linker control file above, the linker performs the following
allocations:
- The four sections (mysect1, mysect2, mysect3, mysect4) are assigned
unique, non-overlapping load addresses in the ROM memory region. This
assignment is determined by the particular load allocations given for each
section.
- Sections mysect1 and mysect2 are assigned the same run address in
RAM.
- Sections mysect3 and mysect4 are assigned the same run address in
RAM.
- The run addresses of mysect1/mysect2 and mysect3/mysect4 are allo-
cated contiguously, as directed by the GROUP statement (subject to align-
ment and blocking restrictions).
To refer to groups and unions, linker diagnostic messages use the notation:
GROUP_n
UNION_n
In this notation, n is a sequential number (beginning at 1) that represents the
lexical ordering of the group or union in the linker control file, without regard
to nesting. Groups and unions each have their own counter.
The linker checks the consistency of load and run allocations specified for
unions, groups, and sections. The following rules are used:
- Run allocations are only allowed for top-level sections, groups, or unions
(sections, groups, or unions that are not nested under any other groups
or unions). The linker uses the run address of the top-level structure to
compute the run addresses of the components within groups and unions.
- As discussed in Section 6.11.1, the linker does not accept a load allocation
for uninitialized sections.
- In most cases, you must provide a load allocation for an initialized section.
However, the linker does not accept a load allocation for an initialized sec-
tion that is located within a group that already defines a load allocator.
- As a shortcut, you can specify a load allocation for an entire group, to de-
termine the load allocations for every initialized section or subgroup
nested within the group. However, a load allocation is accepted for an
entire group only if all of the following conditions are true:
J The group is not nested inside another group that has a load allocator.
6-60
Overlay Pages
The linker supports this feature by providing overlay pages. Each page
represents an address range that must be configured separately with the
MEMORY directive. You can then use the SECTIONS directive to specify the
sections to be mapped into various pages.
Pages are numbered sequentially, beginning with 0. If you do not use the
PAGE option, the linker allocates initialized sections into PAGE 0 (program
memory) and uninitialized sections into PAGE 1 (data memory).
For example, assume that your system can select between two banks of
physical memory for data memory space: address range A00h to FFFFh for
PAGE 1 and 0A00h to 2BFF for PAGE 2. Although only one bank can be
selected at a time, you can initialize each bank with different data. This is how
you use the MEMORY directive to obtain this configuration:
Example 6-12. Memory Directive With Overlay Pages
ÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇ
ÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇ
MEMORY
ÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇ
{
PAGE 0 : ONCHIP : origin = 0800h, length = 0240h
ÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇ
: PROG : origin = 02C00h, length = 0D200h
ÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇ
PAGE 1 : OVR_MEM : origin = 0A00h, length = 02200h
: DATA : origin = 02C00h, length = 0D400h
ÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇÇ
}
PAGE 2 : OVR_MEM : origin = 0A00h, length = 02200h
Figure 6-6. Overlay Pages Defined by Example 6-12 and Example 6-13
.text .bss
FC00h
6-62
Overlay Pages
SECTIONS
{
UNION : run = ONCHIP
{
S1 : load = OVR_MEM PAGE 1
{
s1_load = 0A00h;
s1_start = .;
f1.obj (.text)
f2.obj (.text)
s1_length = . - s1_start;
}
S2 : load = OVR_MEM PAGE 2
{
s2_load = 0A00h;
s2_start = .;
f3.obj (.text)
f4.obj (.text)
s2_length = . - s2_start;
}
}
The four modules of code are f1, f2, f3, and f4. The modules f1 and f2 are
combined into output section S1, and f3 and f4 are combined into output
section S2. The PAGE specifications for S1 and S2 tell the linker to link these
sections into the corresponding pages. As a result, they are both linked to load
address A00h, but in different memory spaces. When the program is loaded,
a loader can configure hardware so that each section is loaded into the
appropriate memory bank.
Output sections S1 and S2 are placed in a union that has a run address in
on-chip RAM. The application must move these sections at run time before
executing them. You can use the symbols s1_load and s1_length to move
section S1, and s2_load and s2_length to move section S2. The special
symbol ”.” refers to the current run address, not the current load address.
Within a page, you can bind output sections or use named memory areas in
the usual way. In Example 6-13, S1 could have been allocated:
This binds S1 at address 1200h in page 1. You can also use page as a qualifier
on the address. For example:
If you do not specify any binding or named memory range for the section, the
linker allocates the section into the page wherever it can (just as it normally
does with a single memory space). For example, S2 could also be specified
as:
S2 : PAGE 2 { . . . }
MEMORY
{
PAGE 0 : name 1 [(attr)] : origin = constant , length = constant;
PAGE n : name n [(attr)] : origin = constant , length = constant;
}
Each page is introduced by the keyword PAGE and a page number, followed
by a colon and a list of memory ranges the page contains. Bold portions must
be entered as shown. Memory ranges are specified in the normal way. You can
define up to 255 overlay pages.
6-64
Overlay Pages
The memory ranges ROM, EPROM, and RAM are all on PAGE 0 (since no
page is specified). XROM and XRAM are on PAGE 1. Note that XROM on
PAGE 1 overlays ROM on PAGE 0, and XRAM on PAGE 1 overlays RAM on
PAGE 0.
In the output link map (obtained with the -m linker option), the listing of the
memory model is keyed by pages. This provides an easy method of verifying
that you specified the memory model correctly. Also, the listing of output
sections has a PAGE column that identifies the memory space into which each
section will be loaded.
MEMORY
{
PAGE 0: PROG: origin = 0x0080 length = 0xFF00
PAGE 1: DATA: origin = 0x0080 length = 0xFF80
}
SECTIONS
{
.text: PAGE = 0
.data: PAGE = 0
.cinit: PAGE = 0 ;cflag option only
.bss: PAGE = 1
}
All .text input sections are concatenated to form a .text output section in the
executable output file, and all .data input sections are combined to form a .data
output section. The .text and .data sections are allocated into configured
memory on PAGE 0, which is the program memory space. All .bss sections are
combined to form a .bss output section. The .bss section is allocated into
configured memory on PAGE 1, which is the data memory space.
If you use a SECTIONS directive, the linker performs no part of the default
allocation. Allocation is performed according to the rules specified by the
SECTIONS directive and the general algorithm described in subsection
6.13.2, General Rules for Output Sections.
6-66
Default Allocation Algorithm
An output section can also be formed when input sections are not specified by
a SECTIONS directive (rule 2). In this case, the linker combines all such input
sections that have the same name into an output section with that name. For
example, suppose the files f1.obj and f2.obj both contain named sections
called Vectors and that the SECTIONS directive does not define an output
section for them. The linker combines the two Vectors sections from the input
files into a single output section named Vectors, allocates it into memory, and
includes it in the output file.
After the linker determines the composition of all output sections, it must allo-
cate them into configured memory. The MEMORY directive specifies which
portions of memory are configured; if there is no MEMORY directive, the linker
uses the default configuration.
1) Output sections for which you have supplied a specific binding address
are placed in memory at that address.
3) Any remaining sections are allocated in the order in which they are
defined. Sections not defined in a SECTIONS directive are allocated in the
order in which they are encountered. Each output section is placed into the
first available memory space, considering alignment where necessary.
Note that the linker pads the end of the final .text section (the grouping of all
.text sections from object files in the application) with a non-parallel NOP.
6-68
Special Section Types (DSECT, COPY, and NOLOAD)
- The DSECT type creates a dummy section with the following qualities:
- A COPY section is similar to a DSECT section, except that its contents and
associated information are written to the output module. The .cinit section
that contains initialization tables for the TMS320C54x C/C++ compiler has
this attribute under the RAM model.
- A NOLOAD section differs from a normal output section in one respect: the
section’s contents, relocation information, and line number information
are not placed in the output module. The linker allocates space for it, and
it appears in the memory map listing.
The symbol should be defined externally. If it is not, the linker defines a new
symbol and enters it into the symbol table. The expression must follow the
rules defined in subsection 6.15.3, Assignment Expressions. Assignment
statements must terminate with a semicolon.
The linker processes assignment statements after it allocates all the output
sections. Therefore, if an expression contains a symbol, the address used for
that symbol reflects the symbol’s address in the executable output file.
For example, suppose a program reads data from one of two tables identified
by two external symbols, Table1 and Table2. The program uses the symbol
cur_tab as the address of the current table. cur_tab must point to either Table1
or Table2. You could accomplish this in the assembly code, but you would need
to reassemble the program to change tables. Instead, you can use a linker
assignment statement to assign cur_tab at link time:
prog.obj /* Input file */
cur_tab = Table1; /* Assign cur_tab to one of the tables */
6-70
Assigning Symbols at Link Time
The “.” symbol refers to the current run address, not the current load address,
of the section.
For example, suppose a program needs to know the address of the beginning
of the .data section. By using the .global directive, you can create an external
undefined variable called Dstart in the program. Then assign the value of “.”
to Dstart:
SECTIONS
{
.text: {}
.data: { Dstart = .; }
.bss: {}
}
This defines Dstart to be the first linked address of the .data section. (Dstart
is assigned before .data is allocated.) The linker will relocate all references to
Dstart.
A special type of assignment assigns a value to the “.” symbol. This adjusts
the SPC within an output section and creates a hole between two input sec-
tions. Any value assigned to “.” to create a hole is relative to the beginning of
the section, not to the address actually represented by “.”. Assignments to “.”
and holes are described in Section 6.16, Creating and Filling Holes, on page
6-74.
- Constants are identified by the linker in the same way as by the assembler.
That is, numbers are recognized as decimal unless they have a suffix (H
The linker supports the C language operators listed in Table 6-3 in order of
precedence. Operators in the same group have the same precedence.
Besides the operators listed in Table 6-3, the linker also has an align operator
that allows a symbol to be aligned on an n-word boundary within an output sec-
tion (n is a power of 2). For example, the expression
. = align(16);
aligns the SPC within the current section on the next 16-word boundary.
Because the align operator is a function of the current SPC, it can be used only
in the same context as “.” —that is, within a SECTIONS directive.
< <= > >= Less than, LT or equal, greater than, Left to right
GT or equal
6-72
Assigning Symbols at Link Time
etext is assigned the first address following the .text output section.
(It marks the end of executable code.)
edata is assigned the first address following the .data output section.
(It marks the end of initialized data tables.)
end is assigned the first address following the .bss output section.
(It marks the end of uninitialized data.)
A section that has raw data is referred to as initialized. This means that the
object file contains the actual memory image contents of the section. When the
section is loaded, this image is loaded into memory at the section’s specified
starting address. The .text and .data sections always have raw data if anything
was assembled into them. Named sections defined with the .sect assembler
directive also have raw data.
By default, the .bss section and sections defined with the .usect directive have
no raw data (they are uninitialized). They occupy space in the memory map
but have no actual contents. Uninitialized sections typically reserve space in
RAM for variables. In the object file, an uninitialized section has a normal sec-
tion header and may have symbols defined in it; however, no memory image
is stored in the section.
Holes can be created only within output sections. Space can exist between
output sections, but such space is not holes. There is no way to fill or initialize
the space between output sections with the SECTIONS directive.
To create a hole in an output section, you must use a special type of linker
assignment statement within an output section definition. The assignment
statement modifies the SPC (denoted by “.”) by adding to it, assigning a greater
value to it, or aligning it on an address boundary. The operators, expressions,
and syntaxes of assignment statements are described in Section 6.15,
Assigning Symbols at Link Time, on page 6-70.
6-74
Creating and Filling Holes
All values assigned to the “.” symbol within a section refer to the relative
address within the section. The linker handles assignments to the “.” symbol
as if the section started at address 0 (even if you have specified a binding
address). Consider the statement . = align(16) in the example. This statement
effectively aligns file3.obj .text to start on a 16-word boundary within outsect.
If outsect is ultimately allocated to start on an address that is not aligned,
file3.obj .text will not be aligned either.
Note that the “.” symbol refers to the current run address, not the current load
address, of the section.
Expressions that decrement “.” are illegal. For example, it is invalid to use the
- = operator in an assignment to “.”. The most common operators used in
assignments to “.” are += and align.
If an output section contains all input sections of a certain type (such as .text),
you can use the following statements to create a hole at the beginning or end
of the output section:
.text: { .+= 100h; } /* Hole at the beginning */
.data: {
*(.data)
. += 100h; } /* Hole at the end */
Uninitialized sections become holes only when they are combined with
initialized sections. If several uninitialized sections are linked together, the
resulting output section is also uninitialized.
6-76
Creating and Filling Holes
3) If you do not specify an initialization value for a hole, the linker fills the hole
with the value specified by the -f option. For example, suppose the
command file link.cmd contains the following SECTIONS directive:
SECTIONS
{
.text: { .= 100; } /* Create a 100-word hole */
}
Now invoke the linker with the -f option:
4) If you do not invoke the linker with the -f option, the linker fills holes with 0s.
Whenever a hole is created and filled in an initialized output section, the hole
is identified in the link map along with the value the linker uses to fill it.
Follow these guidelines for producing a file that you will relink:
- Intermediate link steps should be concerned only with the formation of out-
put sections and not with allocation. All allocation, binding, and MEMORY
directives should be performed in the final link step.
- If the intermediate files have global symbols that have the same name as
global symbols in other files and you wish them to be treated as static
(visible only within the intermediate file), you must link the files with the -h
option (See subsection 6.4.7, Make All Global Symbols Static (-h and -g
global_symbol Options), on page 6-12.)
- If you are linking C code, don’t use -c or -cr until the final link step. Every
time you invoke the linker with the -c or -cr option the linker will attempt
to create an entry point.
The following example shows how you can use partial linking:
Step 1: Link the file file1.com; use the -r option to retain relocation
information in the output file tempout1.out.
lnk500 -r -o tempout1 file1.com
file1.com contains:
SECTIONS
{
ss1: {
f1.obj
f2.obj
.
.
.
fn.obj
}
}
6-78
Partial (Incremental) Linking
Step 2: Link the file file2.com; use the -r option to retain relocation
information in the output file tempout2.out.
lnk500 -r -o tempout2 file2.com
file2.com contains:
SECTIONS
{
ss2: {
g1.obj
g2.obj
.
.
.
gn.obj
}
}
6-80
Linking C/C++ Code
You can also create your own object libraries and link them. The linker includes
and links only those library members that resolve undefined references.
For more information, see subsection 6.4.8, Define Heap Size (-heap
constant Option), on page 6-12, or subsection 6.4.16, Define Stack Size
(-stack constant Option), on page 6-18.
The loader then uses the initialization tables directly from the object file to
initialize variables in .bss.
Figure 6-7 illustrates the RAM autoinitialization model.
.cinit Loader
.bss
Variables are initialized at run time. The .cinit section is loaded into
memory along with all the other sections. The linker defines a special
symbol called cinit that points to the beginning of the tables in memory.
When the program begins running, the C/C++ boot routine copies data
from the tables into the specified variables in the .bss section. This allows
initialization data to be stored in ROM and copied to RAM each time the
program is started.
Figure 6-8 illustrates the ROM autoinitialization model.
6-82
Linking C/C++ Code
Initialization
.cinit Loader tables
(possibly ROM)
Boot
routine
.bss
- The symbol _c_int00 is defined as the program entry point. _c_int00 is the
start of the C/C++ boot routine in boot.obj; referencing _c_int00 ensures
that boot.obj is automatically linked in from the run-time-support library
rts.lib.
- In the ROM model (-c option), the linker defines the symbol cinit as the
starting address of the .cinit section. The C/C++ boot routine uses this
symbol as the starting point for autoinitialization.
J The linker sets the symbol cinit to -1. This indicates that the
initialization tables are not in memory, so no initialization is performed
at run time.
J The STYP_COPY flag (0010h) is set in the .cinit section header.
STYP_COPY is the special attribute that tells the loader to perform
autoinitialization directly and not to load the .cinit section into memory.
The linker does not allocate space in memory for the .cinit section.
6-84
Linker Example
Program Memory
Data Memory
The output sections are constructed from the following input sections:
- The .bss sections from demo.obj. tables.obj, and fft.obj, which contain
variables, must be linked into block RAM_PG of program RAM. The
unused part of this RAM must be initialized to 0FFFFh.
- The xy section from demo.obj, which contains buffers and variables, will
have the default linking into block ONCHIP of data RAM, since it was not
explicitly linked.
Example 6-15 shows the linker command file for this example. Example 6-16
shows the map file.
/***************************************************************/
/*** Specify Linker Options ***/
/***************************************************************/
-e coeff /* Define the program entry point */
-o demo.out /* Name the output file */
-m demo.map /* Create an output map */
/***************************************************************/
/*** Specify the Input Files ***/
/***************************************************************/
demo.obj
fft.obj
tables.obj
/***************************************************************/
/*** Specify the Memory Configurations ***/
/***************************************************************/
MEMORY
{
PAGE 0: RAM_PG: origin=00080h length=06F80h
ROM: origin=0C000h length=03F80h
/****************************************************************/
/*** Specify the Output Sections ***/
/****************************************************************/
SECTIONS
{
.text: load = ROM, page = 0 /* link .text into ROM */
var_defs: load = ONCHIP, page=1 /* defs in RAM */
.data: fill = 07A1Ch, load=ONCHIP, page=1
{
tables.obj(.data) /* .data input */
fft.obj(.data) /* .data input */
. = 100h; /* create hole, fill with 07A1Ch */
} /* and link with ONCHIP */
.bss: load=RAM_PG,page=0,fill=0FFFFh
/* Remaining .bss; fill and link */
}
/***************************************************************/
/*** End of Command File ***/
/***************************************************************/
6-86
Linker Example
MEMORY CONFIGURATION
name origin length used attributes fill
-------- -------- --------- ------- ---------- --------
PAGE 0: RAM_PG 00000080 000006f80 00000002 RWIX
ROM 0000c000 000003f80 00000011 RWIX
PAGE 1: ONCHIP 00000080 000000f7f 00000105 RWIX
EXT 00001000 00000efff 00000000 RWIX
GLOBAL SYMBOLS
address name address name
-------- ---- -------- ----
00000080 .bss 00000080 .bss
00000082 .data 00000082 .data
0000c000 .text 00000082 TEMP
0000c002 ARRAY 0000c002 ARRAY
00000082 TEMP 00000182 end
00000182 edata 0000018a edata
00000082 end 0000c000 .text
0000c011 etext 0000c011 etext
[8 symbols]
Archiver Description
Topic Page
7-1
Archiver Overview
You can build libraries from any type of files. Both the assembler and the linker
accept archive libraries as input; the assembler can use libraries that contain
individual source files, and the linker can use libraries that contain individual
object files.
One of the most useful applications of the archiver is building libraries of object
modules. For example, you can write several arithmetic routines, assemble
them, and use the archiver to collect the object files into a single, logical group.
You can then specify the object library as linker input. The linker will search the
library and include members that resolve external references.
You can also use the archiver to build macro libraries. You can create several
source files, each of which contains a single macro, and use the archiver to
collect these macros into a single, functional group. The .mlib assembler
directive lets you specify the name of a macro library; during the assembly
process, the assembler will search the specified library for the macros that you
call. Chapter 7, Macro Language, discusses macros and macro libraries in
detail.
7-2
Archiver Development Flow
C
source
files
Macro
source
files
C compiler
Translator
Archiver utility
Assembler
source
Macro
library Assembler
source
Assembler
Library-build
COFF utility
object
Archiver
files
Runtime-
support
Library of library
object
files Linker
Debugging
tools
Executable
COFF
file
Hex conversion
utility
7-4
Invoking the Archiver
- If you want to create a library called function.lib that contains the files
sine.obj, cos.obj, and flt.obj, enter:
ar500 -a function sine.obj cos.obj flt.obj
TMS320C54x Archiver Version x.xx
Copyright (c) 2001 Texas Instruments Incorporated
==> new archive ’function.lib’
==> building archive ’function.lib’
- If you want to modify a library member, you can extract it, edit it, and re-
place it. In this example, assume there’s a library named macros.lib that
contains the members push.asm, pop.asm, and swap.asm.
ar500 -x macros push.asm
The archiver makes a copy of push.asm and places it in the current
directory, but it doesn’t remove push.asm from the library. Now you can
edit the extracted file. To replace the copy of push.asm in the library with
the edited copy, enter:
ar500 -r macros push.asm
7-6
Chapter 8
The absolute lister is a debugging tool that accepts linked object files as input
and creates .abs files as output. These .abs files can be assembled to produce
a listing that shows the absolute addresses of object code. Manually, this could
be a tedious process requiring many operations; however, the absolute lister
utility performs these operations automatically.
Topic Page
8-1
Producing an Absolute Listing
ÍÍ
Step 1: Assembler First, assemble a source file.
source file
ÍÍ
ÍÍ
Assembler
ÍÍ
Object
ÍÍ
file
ÍÍ
Step 2: Link the resulting object file.
ÍÍ
Linker
ÍÍ
ÍÍ
Linked object
ÍÍ
file
ÍÍ
Step 3: Invoke the absolute lister; use the linked object
file as input. This creates a file with an .abs
ÍÍ
Absolute extension.
ÍÍ
lister
ÍÍ
ÍÍ
.abs
file
ÍÍ
ÍÍ
Step 4: Finally, assemble the .abs file; you must
invoke the assembler with the -a option. This
ÍÍ
Assembler produces a listing file that contains absolute
ÍÍ
addresses.
Absolute
listing
8-2
Invoking the Absolute Lister
The absolute lister produces an output file for each file that was linked. These
files are named with the input filenames and an extension of .abs. Header files,
however, do not generate a corresponding .abs file.
Assemble these files with the -a assembler option as follows to create the
absolute listing:
asm500 -a filename.abs
The -e options affect both the interpretation of filenames on the command line
and the names of the output files. They should always precede any filename
on the command line.
The -e options are useful when the linked object file was created from C files
compiled with the debugging option (-g compiler option). When the debugging
option is set, the resulting linked object file contains the name of the source
files used to build it. In this case, the absolute lister will not generate a
corresponding .abs file for the C header files. Also, the .abs file corresponding
to a C source file will use the assembly file generated from the C source file
rather than the C source file itself.
For example, suppose the C source file hello.csr is compiled with debugging
set; this generates the assembly file hello.s. hello.csr also includes hello.hsr.
Assuming the executable file created is called hello.out, the following
command will generate the proper .abs file:
abs500 -ea s -ec csr -eh hsr hello.out
An .abs file will not be created for hello.hsr (the header file), and hello.abs will
include the assembly file hello.s, not the C source file hello.csr.
8-4
Absolute Lister Example
module1.asm
.text
.bss array,100
.bss dflag, 2
.copy globals.def
ld #offset, A
ld dflag, A
module2.asm
.bss offset, 2
.copy globals.def
ld #offset, A
ld #array, A
globals.def
.global dflag
.global array
.global offset
The following steps create absolute listings for the files module1.asm and
module2.asm:
Step 1: First, assemble module1.asm and module2.asm:
asm500 module1
asm500 module2
This creates two object files called module1.obj and module2.obj.
Step 2: Next, link module1.obj and module2.obj using the following linker
command file, called bttest.cmd:
/************************************************/
/* File bttest.cmd -- COFF linker command file */
/* for linking TMS320C54x modules */
/*********************************** ************/
-o bttest.out /* Name the output file */
-m bttest.map /* Create an output map */
/************************************************/
/* Specify the Input Files */
/************************************************/
module1.obj
module2.obj
/************************************************/
/* Specify the Memory Configurations */
/************************************************/
MEMORY
{
PAGE 0: ROM: origin=2000h length=2000h
PAGE 1: RAM: origin=8000h length=8000h
}
/************************************************/
/* Specify the Output Sections */
/************************************************/
SECTIONS
{
.data: >RAM PAGE 1
.text: >ROM PAGE 0
.bss: >RAM PAGE 1
}
8-6
Absolute Lister Example
Step 4: Finally, assemble the .abs files created by the absolute lister
(remember that you must use the -a option when you invoke the
assembler):
asm500 -a module1.abs
asm500 -a module2.abs
This creates two listing files called module1.lst and module2.lst; no
object code is produced. These listing files are similar to normal
listing files; however, the addresses shown are absolute addresses.
The absolute listing files created are module1.lst (see Figure 8-2)
and module2.lst (see Figure 8-3).
8-8
Absolute Lister Example
The cross-reference lister is a debugging tool. This utility accepts linked object
files as input and produces a cross-reference listing as output. This listing
shows symbols, their definitions, and their references in the linked source files.
Topic Page
9-1
Producing a Cross-Reference Listing
ÍÍ
Step 1: Assembler First, invoke the assembler with the -x option.
source file
ÍÍ
This option produces a cross-reference table
in the listing file and adds to the object file
ÍÍ
Assembler assembler cross-references only global sym-
ÍÍ
bols. If you use the -s option when invoking
the assembler, it will cross-reference local
ÍÍ variables as well.
ÍÍ
Object
ÍÍ
file
ÍÍ
Step 2: Link the object file (.obj) to obtain an execut-
able object file (.out).
Linker
ÍÍ
ÍÍ
ÍÍ
Linked object
file
Step 3:
ÍÍ Invoke the cross-reference lister. The follow-
ing section provides the command syntax for
ÍÍ
Cross-reference invoking the cross-reference lister utility.
lister
ÍÍ
ÍÍ
Cross-reference
listing
9-2
Invoking the Cross-Reference Lister
================================================================================
Symbol: INIT
Symbol: X
Symbol: Y
================================================================================
Symbol: Z
================================================================================
9-4
Cross-Reference Listing Example
RTYP The symbol’s reference type in this file. The possible refer-
ence types are:
RefLn The line number where the symbol is referenced. If the line
number is followed by an asterisk(*), then that reference
may modify the contents of the object. If the line number
is followed by a letter (such as A, B, or C), the symbol is
referenced in a file specified by a .include directive in the
assembly source. “A” is assigned to the first file specified
by a .include directive; “B” is assigned to the second file,
etc. A blank in this column indicates that the symbol was
never used.
Table 9-1 lists the symbol attributes that appear in the cross-reference listing
example.
Character Meaning
’ Symbol defined in a .text section
9-6
Chapter 10
Hex&Conversion&Utility&Description
The TMS320C54xt assembler and linker create object files that are in
common object file format (COFF). COFF is a binary object file format that
encourages modular programming and provides more powerful and flexible
methods for managing code segments and target system memory.
Most EPROM programmers do not accept COFF object files as input. The hex
conversion utility converts a COFF object file into one of several standard
ASCII hexadecimal formats, suitable for loading into an EPROM programmer.
The utility is also useful in other applications requiring hexadecimal conversion
of a COFF object file (for example, when using debuggers and loaders). This
utility also supports the on-chip boot loader built into the target device,
automating the code creation process for the C54x.
The hex conversion utility can produce these output file formats:
- ASCII-Hex, supporting 16-bit addresses
- Extended Tektronix (Tektronix)
- Intel MCS-86 (Intel)
- Motorola Exorciser (Motorola-S), supporting 16-bit, 24-bit, and 32-bit
addresses
- Texas Instruments SDSMAC (TI-Tagged), supporting 16-bit addresses
Topic Page
10.1 Hex Conversion Utility Development Flow . . . . . . . . . . . . . . . . . . . . 10-2
10.2 Invoking the Hex Conversion Utility . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3
10.3 Command File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-7
10.4 Understanding Memory Widths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-9
10.5 The ROMS Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-16
10.6 The SECTIONS Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22
10.7 Output Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-24
10.8 Image Mode and the -fill Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-26
10.9 Building a Table for an On-Chip Boot Loader . . . . . . . . . . . . . . . . . 10-28
10.10 Controlling the ROM Device Address . . . . . . . . . . . . . . . . . . . . . . . . 10-35
10.11 Description of the Object Formats . . . . . . . . . . . . . . . . . . . . . . . . . . 10-39
10.12 Hex Conversion Utility Error Messages . . . . . . . . . . . . . . . . . . . . . . 10-45
10-1
Hex Conversion Utility Development Flow
C
source
files
Macro
source
files
C compiler
Translator
Archiver utility
Assembler
source
Macro
library Assembler
source
Assembler
Library-build
COFF utility
object
Archiver
files
Runtime-
support
Library of library
object
files Linker
Debugging
tools
Executable
COFF
file
Hex conversion
utility
EPROM Cross-reference
programmer Absolute lister ’C5000
lister
10-2
Invoking the Hex Conversion Utility
There are two basic methods for invoking the hex conversion utility:
- Specify the options and filenames on the command line. The following
example converts the file firmware.out into TI-Tagged format, producing
two output files, firm.lsb and firm.msb.
hex500 -t firmware -o firm.lsb -o firm.msb
- Specify the options and filenames in a command file. You can create
a batch file that stores command line options and filenames for invoking
the hex conversion utility. The following example invokes the utility using
a command file called hexutil.cmd:
hex500 hexutil.cmd
In addition to regular command line information, you can use the hex
conversion utility ROMS and SECTIONS directives in a command file.
The general options control the overall operation of the hex conversion utility.
The memory options configure the memory widths for your output files.
-romwidth value Specify the ROM device width (default depends on 10-11
format used)
10-4
Invoking the Hex Conversion Utility
The boot-loader options for all C54x devices control how the hex conversion
utility builds the boot table.
-bootorg PARALLEL Specify the source of the boot loader table as the 10-29
parallel port
-bootorg SERIAL Specify the source of the boot loader table as the 10-29
serial port
-bootorg value Specify the source address of the boot loader table 10-30
-bootpage value Specify the target page number of the boot loader 10-30
table
-bootorg COMM Specify the source of the boot loader table as the 10-29
communications port
-spc value Set the serial port control register value 10-29
-spce value Set the serial port control extension register value 10-29
-arr value Set the ABU receive address register value 10-29
-bkr value Set the ABU transmit buffer size register value 10-29
-tcsr value Set the TDM serial port channel select register 10-29
value
-trta value Set the TDM serial port receive/transmit address 10-29
register value
-swwsr value Set the Software Wait State Reg value for 10-29
PARALLEL/WARM boot mode
-bscr value Set the Bank-Switch Control Reg value for 10-29
PARALLEL/WARM boot mode
10-6
Command File
Command files are ASCII files that contain one or more of the following:
- ROMS directive. The ROMS directive defines the physical memory con-
figuration of your system as a list of address-range parameters. (For more
information about the ROMS directive, see Section 10.5, The ROMS
Directive, on page 10-16.)
- Comments. You can add comments to your command file by using the /*
and */ delimiters. For example:
/* This is a comment */
To invoke the utility and use the options you defined in a command file, enter:
hex500 command_filename
You can also specify other options and files on the command line. For exam-
ple, you could invoke the utility by using both a command file and command
line options:
hex500 firmware.cmd -map firmware.mxp
The order in which these options and file names appear is not important. The
utility reads all input from the command line and all information from the
command file before starting the conversion process. However, if you are
using the -q option, it must appear as the first option on the command line or
in a command file.
The -q option suppresses the utility’s normal banner and progress informa-
tion.
- This example converts a file called appl.out into four hex files in Intel
format. Each output file is one byte wide and 16K bytes long. The .text
section is converted to boot loader format.
appl.out /* input file */
-i /* Intel format */
-map appl.mxp /* map file */
ROMS
{
ROW1: origin=01000h len=04000h romwidth=8
files={ appl.u0 appl.u1 }
ROW2: origin 05000h len=04000h romwidth=8
files={ app1.u2 appl.u3 }
}
SECTIONS
{ .text: BOOT
.data, .cinit, .sect1, .vectors, .const:
}
10-8
Understanding Memory Widths
The hex conversion utility makes your memory architecture more flexible by
allowing you to specify memory and ROM widths. In order to use the hex
conversion utility, you must understand how the utility treats word widths. Four
widths are important in the conversion process: target width, data width,
memory width, and ROM width. The terms target word, data word, memory
word, and ROM word refer to a word of such a width.
Figure 10-2 illustrates the three separate and distinct phases of the hex
conversion utility’s process flow.
Output file(s)
The hex conversion utility defaults memory width to the target width (in this
case, 16 bits).
- Using the -memwidth option. This changes the memory width value for
the entire file.
For both methods, use a value that is a power of 2 greater than or equal to 8.
You should change the memory width default value of 16 only in exceptional
situations: for example, when you need to break single target words into
consecutive, narrower memory words. Situations in which memory words are
narrower than target words are most common when you use an on-chip boot
loader that supports booting from narrower memory. For example, a 16-bit
TMS320C54x can be booted from 8-bit memory or an 8-bit serial port, with
each 16-bit value occupying two memory locations (this would be specified as
-memwidth 8).
10-10
Understanding Memory Widths
Figure 10-3 demonstrates how the memory width is related to the data width.
Source file
.word 0AABBh
.word 01122h
. . .
Data width = 16 (fixed)
For example, for a memory width of 16, you could specify a ROM width of 16
and get a single output file containing 16-bit words. Or you can use a ROM
width value of 8 to get two files, each containing 8 bits of each word.
For more information on calculating the number of files per address range, see
Section 10.5, The ROMS Directive, on page 10-16.
The default ROM width that the hex conversion utility uses depends on the out-
put format:
- All hex formats except TI-Tagged are configured as lists of 8-bit bytes; the
default ROM width for these formats is 8 bits.
- Using the -romwidth option. This changes the ROM width value for the
entire COFF file.
- Setting the romwidth parameter of the ROMS directive. This changes the
ROM width value for a specific ROM address range and overrides the
-romwidth option for that range. See Section 10.5, The ROMS Directive,
on page 10-16.
For both methods, use a value that is a power of 2 greater than or equal to 8.
If you select a ROM width that is wider than the natural size of the output format
(16 bits for TI-Tagged or 8 bits for all others), the utility simply writes multibyte
fields into the file.
Figure 10-4 illustrates how the target, memory, and ROM widths are related
to one another.
10-12
Understanding Memory Widths
Source file
.word 0AABBCDDh
.word 01122344h
. . .
Data width = 16 (fixed)
Data after 0AABBh
phase I
of hex utility 01122h
. . .
Memory widths (variable)
-memwidth 16 -memwidth 8
Data after AABB BB
phase II
of hex utility 1122 AA
. . .
22
11
. . .
Output files
-romwidth 16
-o file.wrd AABB1122 . . .
-romwidth 8
-o file.byt BBAA2211 . . .
CPU
AAh BBh
128K x 8 128K x 8
ROM0 ROM1
By default, the utility uses little-endian format because the C54x boot loaders
expect the data in this order. Unless you are using your own boot loader pro-
gram, avoid using -order MS.
10-14
Understanding Memory Widths
- This option applies only when you use a memory width with a value less
than 16. Otherwise, -order is ignored.
- This option does not affect the way memory words are split into output
files. Think of the files as a set: the set contains a least significant file and
a most significant file, but there is no ordering over the set. When you list
filenames for a set of files, you always list the least significant first, regard-
less of the -order option.
Figure 10-6 demonstrates how -order affects the conversion process. This
figure, and the previous figure, Figure 10-4, explain the condition of the data
in the hex conversion utility output files.
Source file
.word 0AABBh
.word 01122h
. . .
Target width = 16 (fixed)
0AABBh
01122h
. . .
Memory widths (variable)
-memwidth 8 -memwidth 8
-order LS (default) -order MS
BB AA
AA BB
22 11
11 22
. . . . . .
Each address range produces one set of files containing the hex conversion
utility output data that corresponds to that address range. Each file can be
used to program one single ROM device.
If you do not use a ROMS directive, the utility defines a default memory config-
uration that includes two address spaces (PAGE 0 and PAGE 1). Each address
space contains a single address range. PAGE 0 contains a default range of the
entire program address space, and PAGE 1 contains a default range of the en-
tire data address space.
ROMS
{
[PAGE n:]
romname: [origin=value,] [length=value,] [romwidth=value,]
[memwidth=value,] [fill=value,]
[files={filename1, filename2, ...}]
10-16
The ROMS Directive
files identifies the names of the output files that correspond to this
range. Enclose the list of names in curly braces and order them
from least significant to most significant output file.
The number of file names should equal the number of output
files that the range will generate. To calculate the number of
output files, refer to Section 10.4.4, ROM Width, on page
10-11. The utility warns you if you list too many or too few file-
names.
Unless you are using the -image option, all of the parameters defining a range
are optional; the commas and equals signs are also optional. A range with no
origin or length defines the entire address space. In image mode, an origin and
length are required for all ranges.
Ranges on the same page must not overlap and must be listed in order of
ascending address.
10-18
The ROMS Directive
a range contains data for the whole range. Gaps before, between, or after
sections are filled with the fill value from the ROMS directive, with the value
specified with the -fill option, or with the default value of 0.
infile.out
-image
-memwidth 16
ROMS
{
EPROM1: org = 04000h, len = 02000h, romwidth = 8
files = { rom4000.b0, rom4000.b1 }
In this example, EPROM1 defines the address range from 4000h through
5FFFh. The range contains the following sections:
The rest of the range is filled with 0h (the default fill value). The data from this
range is converted into two output files:
- rom4000.b0 contains bits 0 through 7
- rom4000.b1 contains bits 8 through 15
EPROM2 defines the address range from 6000h through 7FFFh. The range
contains the following sections:
The rest of the range is filled with 0FFh (from the specified fill value). The data
from this range is converted into two output files:
- rom6000.b0 contains bits 0 through 7
- rom6000.b1 contains bits 8 through 15
Figure 10-7 shows how the ROMS directive partitions the infile.out file into
four output files.
Figure 10-7. The infile.out File From Example 10-1 Partitioned Into Four Output Files
ÉÉÉÉÉÉÉÉ
.text .text .text
ÉÉÉÉÉÉÉÉ
0487Fh
04880h
ÉÉÉÉÉÉÉÉ
05B80h 0h 0h
.data 05B80h
.data .data
0633Fh 05FFFh
06700h
width = 8 bits len =
2000h (8K)
.table
EPROM2
ÉÉÉÉÉÉÉÉ
07C7Fh rom6000.b0 rom6000.b1
ÉÉÉÉÉÉÉÉ
06000h .data .data
06340h
0FFh 0FFh
memwidth = 16 bits 06700h
.table .table
ÉÉÉÉÉÉÉÉ
07C80h
07FFFh ÉÉÉÉÉÉÉÉ
0FFh 0FFh
10-20
The ROMS Directive
Example 10-2. Map File Output From Example 10-1 Showing Memory Ranges
-----------------------------------------------------
00004000..00005fff Page=0 Width=8 ”EPROM1”
-----------------------------------------------------
OUTPUT FILES: rom4000.b0 [b0..b7]
rom4000.b1 [b8..b15]
- If you use a SECTIONS directive, the utility converts only the sections that
you list in the directive and ignores all other sections in the COFF file.
- If you don’t use a SECTIONS directive, the utility converts all initialized
sections that fall within the configured memory. The TMS320C54x
compiler-generated initialized sections include: .text, .const, .cinit, and
.switch.
Uninitialized sections are never converted, whether or not you specify them
in a SECTIONS directive.
Use the SECTIONS directive in a command file. (For more information about
using a command file, see Section 10.3, Command Files, on page 10-7.) The
general syntax for the SECTIONS directive is:
SECTIONS
{
sname: [paddr=value]
sname: [paddr=boot]
sname: [= boot ],
...
}
10-22
The SECTIONS Directive
The commas separating section names are optional. For more similarity with
the linker’s SECTIONS directive, you can use colons after the section names
(in place of the equal sign on the boot keyboard). For example, the following
statements are equivalent:
In the example below, the COFF file contains six initialized sections: .text,
.data, .const, .vectors, .coeff, and .tables. Suppose you want only .text and
.data to be converted. Use a SECTIONS directive to specify this:
To configure both of these sections for boot loading, add the boot keyword:
1) It looks for the ROMS directive. If a file is associated with a range in the
ROMS directive and you have included a list of files (files = {. . .}) on that
range, the utility takes the filename from the list.
For example, assume that the target data is 16-bit words being converted
to two files, each eight bits wide. To name the output files using the ROMS
directive, you could specify:
ROMS
{
RANGE1: romwidth=8, files={ xyz.b0 xyz.b1 }
}
The utility creates the output files by writing the least significant bits (LSBs)
to xyz.b0 and the most significant bits (MSBs) to xyz.b1.
2) It looks for the -o options. You can specify names for the output files by
using the -o option. If no filenames are listed in the ROMS directive and
you use -o options, the utility takes the filename from the list of -o options.
The following line has the same effect as the example above using the
ROMS directive:
-o xyz.b0 -o xyz.b1
Note that if both the ROMS directive and -o options are used together, the
ROMS directive overrides the -o options.
10-24
Output Filenames
In image mode, there are no discontinuities. Each output file contains a contin-
uous stream of data that corresponds exactly to an address range in target
memory. Any gaps before, between, or after sections are filled with a fill value
that you supply.
An output file converted by using image mode still has address records
because many of the hexadecimal formats require an address on each line.
However, in image mode, these addresses will always be contiguous.
10-26
Image Mode and the -fill Option
The hex conversion utility uses a default fill value of zero if you don’t specify
a value with the fill option. The -fill option is valid only when you use -image;
otherwise, it is ignored.
Step 2: Invoke the hex conversion utility with the -image option. To number
the bytes sequentially, use the -byte option; to reset the address
origin to zero for each output file, use the -zero option. See
subsection 10.10.3, The -byte Option, on page 10-37 for details on
the -byte option, and page 10-36 for details on the -zero option. If
you don’t specify a fill value with the ROMS directive and you want
a value other than the default of zero, use the -fill option.
Some DSP devices, such as the C54x, have a built-in boot loader that initial-
izes memory with one or more blocks of code or data. The boot loader uses
a special table (a boot table) stored in memory (such as EPROM) or loaded
from a device peripheral (such as a serial or communications port) to initialize
the code or data. The hex conversion utility supports the boot loader by auto-
matically building the boot table.
The input for a boot loader is the boot table. The boot table contains records
that instruct the on-chip loader to copy blocks of data contained in the table to
specified destination addresses. Some boot tables also contain values for ini-
tializing various processor control registers. The boot table can be stored in
memory or read in through a device peripheral.
The hex conversion utility automatically builds the boot table for the boot
loader. Using the utility, you specify the COFF sections you want the boot
loader to initialize, the table location, and the values for any control registers.
The hex conversion utility identifies the target device type from the COFF file,
builds a complete image of the table according to the format required by that
device, and converts it into hexadecimal in the output files. Then, you can burn
the table into ROM or load it by other means.
The boot loader supports loading from memory that is narrower than the nor-
mal width of memory. For example, you can serially boot a 16-bit TMS320C54x
from a single 8-bit EPROM by using the -serial8-memwidth option to config-
ure the width of the boot table. The hex conversion utility automatically adjusts
the table’s format and length. See the boot loader example in the
TMS320C54x DSP Reference Set for an illustration of a boot table.
The boot table format is simple. Typically, there is a header record containing
values for various control registers. Each subsequent block has a header con-
taining the size and destination address of the block followed by data for the
block. Multiple blocks can be entered; a termination block follows the last
block. Finally, the table can have a footer containing more control register val-
ues. See the boot loader section in the TMS320C54x DSP Reference Set for
more information.
10-28
Building a Table for an On-Chip Boot Loader
Option Description
-boot Convert all sections into bootable form (use instead of a
SECTIONS directive)
-bootorg PARALLEL Specify the source of the boot loader table as the parallel
port
-bootorg SERIAL Specify the source of the boot loader table as the serial port
-bootorg value Specify the source address of the boot loader table
-bootpage value Specify the target page number of the boot loader table
-e value Specify the entry point at which to begin execution after boot
loading. The value can be an address or a global symbol.
Option Description
-bootorg WARM Specify the source of the boot loader table as the table cur-
or -warm rently in memory
-bootorg COMM Specify the source of the boot loader table as the commu-
nications port
-spce value Set the serial port control extension register value
-bkr value Set the ABU transmit buffer size register value
-tcsr value Set the TDM serial port channel select register value
-trta value Set the TDM serial port receive/transmit address register
value
-swwsr value Set the software wait state register value for PARALLEL/
WARM boot mode
-bscr value Set the bank-switch control register value for PARALLEL/
WARM boot mode
Step 1: Link the file. Each block of the boot table data corresponds to an
initialized section in the COFF file. Uninitialized sections are not con-
verted by the hex conversion utility (see Section 10.6, The
SECTIONS Directive, on page 10-22).
When you select a section for placement in a boot-loader table, the
hex conversion utility places the section’s load address in the des-
tination address field for the block in the boot table. The section
content is then treated as raw data for that block.
10-30
Building a Table for an On-Chip Boot Loader
The hex conversion utility does not use the section run address.
When linking, you need not worry about the ROM address or the
construction of the boot table—the hex conversion utility handles
this.
Step 2: Identify the bootable sections. You can use the -boot option to tell
the hex conversion utility to configure all sections for boot loading.
Or, you can use a SECTIONS directive to select specific sections to
be configured (see Section 10.6, The SECTIONS Directive, on page
10-22). Note that if you use a SECTIONS directive, the -boot option
is ignored.
Step 3: Set the ROM address of the boot table. Use the -bootorg option
to set the source address of the complete table. For example, if you
are using the C54x and booting from memory location 8000h, specify
-bootorg 8000h. The address field in the the hex conversion utility
output file will then start at 8000h.
If you use -bootorg SERIAL or -bootorg PARALLEL, or if you do not
use the -bootorg option at all, the utility places the table at the origin
of the first memory range in a ROMS directive. If you do not use a
ROMS directive, the table will start at the first section load address.
There is also a -bootpage option for starting the table somewhere
other than page 0.
The complete boot table is similar to a single section containing all of the
header records and data for the boot loader. The address of this “section” is
the boot table origin. As part of the normal conversion process, the hex
conversion utility converts the boot table to hexadecimal format and maps it
into the output files like any other section.
Be sure to leave room in your system memory for the boot table, especially
when you are using the ROMS directive. The boot table cannot overlap other
nonboot sections or unconfigured memory. Usually, this is not a problem; typi-
cally, a portion of memory in your system is reserved for the boot table. Simply
configure this memory as one or more ranges in the ROMS directive, and use
the -bootorg option to specify the starting address.
For example, if you want your program to start running at address 0123h after
loading, specify -e 0123h on the command line or in a command file. You can
determine the -e address by looking at the map file that the linker generates.
10-32
Building a Table for an On-Chip Boot Loader
When you use the -e option, the utility builds a dummy block of length 1 and
data value 0 that loads at the specified address. Your blocks follow this dummy
block. Since the dummy block is loaded first, the dummy value of 0 is over-
written by the subsequent blocks. Then, the boot loader jumps to the -e option
address after the boot load is completed.
When using the -bootorg WARM option, the -e option sets the address of
where the boot table is loaded in ROM.
The C54x boot loader has several different modes. You can select these
modes by using the -bootorg and -memwidth options:
You should set the -romwidth equal to the -memwidth unless you want to have
multiple output files.
The C54x can boot through either the serial or parallel interface with either 8-
or 16-bit data. The format is the same for any combination: the boot table
consists of a field containing the destination address, a field containing the
length, and a block containing the data.
You can boot only one section. If you are booting from an 8-bit channel, 16-bit
words are stored in the table with the MSBs first; the hex conversion utility
automatically builds the table in the correct format.
- To boot from a serial port, specify -bootorg SERIAL when invoking the
utility. Use either -memwidth 8 or -memwidth 16.
- To load from a parallel I/O port, invoke the utility by specifying -bootorg
PARALLEL. Use either -memwidth 8 or -memwidth 16.
For example, the command file in Figure 10-8 allows you to boot the .text
section of abc.out from a byte-wide EPROM at location 0x8000.
Figure 10-8. Sample Command File for Booting From a C54x EPROM
10-34
Controlling the ROM Device Address
Non-boot loader mode. The address field of the hex conversion utility output
file is controlled by the following mechanisms listed from low to high priority:
1) The linker command file. By default, the address field of the hex conver-
sion utility output file is a function of the load address (as given in the linker
command file) and the hex conversion utility parameter values. The rela-
tionship is summarized as follows:
The value of data width divided by memory width is a correction factor for
address generation. When data width is larger than memory width, the
correction factor expands the address space. For example, if the load
address is 01 and data width divided by memory width is 2, the output file
address field would be 02. The data is split into two consecutive loca-
tions the size of the memory width.
the section load address and places the section in the address specified
by paddr. The relationship between the hex conversion utility output file
address field and the paddr parameter can be summarized as follows:
The value of data width divided by memory width is a correction factor for
address generation. The section beginning load address factor subtracted
from the load address is an offset from the beginning of the section.
3) The -zero option. When you use the -zero option, the utility resets the
address origin to 0 for each output file. Since each file starts at 0 and
counts upward, any address records represent offsets from the beginning
of the file (the address within the ROM) rather than actual target addresses
of the data.
You must use the -zero option in conjunction with the -image option to
force the starting address in each output file to be zero. If you specify the
-zero option without the -image option, the utility issues a warning and
ignores the -zero option.
Boot-Loader Mode. When the boot loader is used, the hex conversion utility
places the different COFF sections that are in the boot table into consecutive
memory locations. Each COFF section becomes a boot table block whose
destination address is equal to the linker-assigned section load address.
In a boot table, the address field of the the hex conversion utility output file is
not related to the section load addresses assigned by the linker. The address
fields of the boot table are simply offsets to the beginning of the table, multi-
plied by the correction factor (data width divided by memory width). The
section load addresses assigned by the linker will be encoded into the boot
table along with the size of the section and the data contained within the
section. These addresses will be used to store the data into memory during
the boot load process.
The beginning of the boot table defaults to the linked load address of the first
bootable section in the COFF input file, unless you use one of the following
mechanisms, listed here from low to high priority. Higher priority mechanisms
override the values set by low priority options in an overlapping range.
10-36
Controlling the ROM Device Address
1) The ROM origin specified in the ROMS directive. The hex conversion
utility places the boot table at the origin of the first memory range in a
ROMS directive.
2) The -bootorg option. The hex conversion utility places the boot table at
the address specified by the -bootorg option if you select boot loading
from memory. Neither -bootorg PARALLEL nor -bootorg SERIAL affect
the address field.
The -byte option causes the address records in an output file to refer to byte
locations within the file, whether the target processor is byte-addressable or
not.
For example, assume you want to load a COFF section (.sec1) at address
0x0100 of an 8-bit EPROM. If you specify the load address in the linker com-
mand file at location 0x0100, the hex conversion utility will multiply the address
by 2 (data width divided by memory width = 16/8 = 2), giving the output file a
starting address of 0x0200. Unless you control the starting address of the
EPROM with your EPROM programmer, you could create holes within the
EPROM. The programmer will burn the data starting at location 0x0200
instead of 0x0100. To solve this, you can:
- Use the paddr parameter of the SECTIONS directive. This forces a sec-
tion to start at the specified value. Figure 10-9 shows a command file that
can be used to avoid the hole at the beginning of .sec1.
Figure 10-9. Hex Command File for Avoiding a Hole at the Beginning of a Section
-i
a.out
-map a.map
ROMS
{
ROM : org = 0x0100, length = 0x200, romwidth = 8,
memwidth = 8
}
SECTIONS
{
sec1: paddr = 0x100
}
Note: If your file contains multiple sections, and, if one section uses a paddr parameter,
then all sections must use the paddr parameter.
- Use the -bootorg option or use the ROMS origin parameter (for boot
loading only). As described on page 10-36, when you are boot loading,
the EPROM address of the entire boot-loader table can be controlled by
the -bootorg option or by the ROMS directive origin.
10-38
Description of the Object Formats
- If you use more than one of these options, the last one you list overrides
the others.
Address Default
Option Format Bits Width
-a ASCII-Hex 16 8
-i Intel 32 8
-m1 Motorola-S1 16 8
-m2 or -m Motorola-S2 24 8
-m3 Motorola-S3 32 8
-t TI-Tagged 16 16
-x Tektronix 32 8
Address bits determine how many bits of the address information the format
supports. Formats with 16-bit addresses support addresses up to 64K only.
The utility truncates target addresses to fit in the number of available bits.
The default width determines the default output width. You can change the
default width by using the -romwidth option or by using the romwidth param-
eter in the ROMS directive. You cannot change the default width of the TI-
Tagged format, which supports a 16-bit width only.
^B $AXXXX,
XX XX XX XX XX XX XX XX XX XX. . .^C
Data byte
The file begins with an ASCII STX character (ctrl-B, 02h) and ends with an
ASCII ETX character (ctrl-C, 03h). Address records are indicated with
$AXXXX, in which XXXX is a 4-digit (16-bit) hexadecimal address. The
address records are present only in the following situations:
- When discontinuities occur
- When the byte stream does not begin at address 0
You can avoid all discontinuities and any address records by using the -image
and -zero options. The output created is a list of byte values.
10-40
Description of the Object Formats
01 End-of-file record
Record type 00, the data record, begins with a colon ( : ) and is followed by the
byte count, the address of the first data byte, the record type (00), and the
checksum. Note that the address is the least significant 16 bits of a 32-bit
address; this value is concatenated with the value from the most recent 04
(extended linear address) record to create a full 32-bit address. The checksum
is the 2s complement (in binary form) of the preceding bytes in the record,
including byte count, address, and data bytes.
Record type 01, the end-of-file record, also begins with a colon ( : ), followed
by the byte count, the address, the record type (01), and the checksum.
Record type 04, the extended linear address record, specifies the upper 16
address bits. It begins with a colon ( : ), followed by the byte count, a dummy
address of 0h, the record type (04), the most significant 16 bits of the address,
and the checksum. The subsequent address fields in the data records contain
the least significant bits of the address.
Figure 10-11 illustrates the Intel hexadecimal object format.
Checksum
Byte Record End-of-file
count type record
The byte count is the character pair count in the record, excluding the type and
byte count itself.
The checksum is the least significant byte of the 1s complement of the sum
of the values represented by the pairs of characters making up the byte count,
address, and the code/data fields.
Type
S00B00004441544120492F4FF3 Header
Record
S1130000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC
S1130010FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED Data
S1130020FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC Records
S1130030FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC
S1130040FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC
S9030000FC Termination
Record
Byte Checksum
Count
Address
10-42
Description of the Object Formats
7 followed by a checksum
Figure 10-13 illustrates the tag characters and fields in TI-Tagged object
format.
K000COFFTOTI90000BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7EF3DF
BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7EE37F Data
BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7F245F records
:
End-of-file Data
record words Checksum
If any data fields appear before the first address, the first field is assigned
address 0000h. Address fields may be expressed for any data byte, but none
is required. The checksum field, which is preceded by the tag character 7, is
a 2s complement of the sum of the 8-bit ASCII values of characters, beginning
with the first tag character and ending with the checksum tag character (7 or
8). The end-of-file record is a colon ( : ).
The header field in the data record contains the following information:
Number of
ASCII
Item Characters Description
% 1 Data type is Tektronix format
Block length 2 Number of characters in the record, minus the %
The load address in the data record specifies where the object code will be
located. The first digit specifies the address length; this is always 8. The
remaining characters of the data record contain the object code, two charac-
ters per byte.
Header %15621810000000202020202020
character
Load address: 10000000h
Block type: 6 Length of
(data) load address
10-44
Hex Conversion Utility Error Messages
sections overlapping
Description Two or more COFF section load addresses overlap or a boot
table address overlaps another section.
Action This problem may be caused by an incorrect translation from
load address to hex output file address that is performed by the
hex conversion utility when memory width is less than data
width. See Section 10.4, Understanding Memory Widths, on
page 10-9 and Section 10.10, Controlling the ROM Device
Address, on page 10-35.
Topic Page
11-1
Translator Overview
11-2
Translator Development Flow
C
source
files
Macro
source files
C compiler
Archiver Mnemonic-to-
Assembler
algebraic
source
translator
Macro
library Assembler
Assembler
source
Library-build
COFF
utility
Archiver object files
Runtime-
support library
Library of object
files Linker
Debugging
tools
Executable
COFF file
Hex conversion
utility
11-4
Translation Modes
Translation: Translator
Translation: Translator
11-6
Translation Modes
file.asm
********************************
.asg *AR0,sym
mymac sym,A
********************************
; mymac sym,A
LD *AR0,A
ADD *AR0,5,A,B
*********************************
; mymac sym,A
A = *AR0
B = A + *AR0 << 5
********************************
- Directives in macros
- Macro local variables
- Defining labels when invoking a macro
mymac 5
; mymac 5
.word 5
11-8
How the Translator Works With Macros
mymac 4
mymac 40
mymac 400
; mymac 4
lab$1$ .word 4
; mymac 40
lab$2$ .word 40
; mymac 400
lab$3$ .word 400
The local label name is appended with $n$, where n is the number of the macro
invocation. Insure that there are no other labels that could be identical to a
generated macro local label.
mymac .macro
.word F403
.endm
LABEL mymac
mymac .macro
.word F403
.endm
;LABEL mymac
.word F403
LABEL is not defined when the code is assembled. Insure that label definitions
do not appear on the same line as the macro invocations. Rewrite the source
code in the example above as follows:
mymac .macro
.word F403
.endm
LABEL
mymac
11-10
Appendix
AppendixAA
The compiler, assembler, and linker create object files in common object file
format (COFF). COFF is an implementation of an object file format of the same
name that was developed by AT&T for use on UNIX-based systems. This for-
mat is used because it encourages modular programming and provides more
powerful and flexible methods for managing code segments and target system
memory.
This appendix contains technical details about COFF object file structure.
Much of this information pertains to the symbolic debugging information that
is produced by the C/C++ compiler. The purpose of this appendix is to provide
supplementary information about the internal format of COFF object files.
Topic Page
A-1
COFF File Structure
The assembler and linker produce object files with the same COFF structure;
however, a program that is linked for the final time does not usually contain
relocation entries. Figure A-1 illustrates the overall object file structure.
file header
optional file header
section 1 header
section headers
section n header
section 1
raw data
raw data
(executable code
section n and initialized data)
raw data
section 1
relocation information
relocation
information
section n
relocation information
section 1
line numbers
line-number
entries
section n
line numbers
symbol table
string table
A-2
COFF File Structure
Figure A-2 shows a typical example of a COFF object file that contains the
three default sections, .text, .data, and .bss, and a named section (referred to
as <named>). By default, the tools place sections into the object file in the
following order: .text, .data, initialized named sections, .bss, and uninitialized
named sections. Although uninitialized sections have section headers, notice
that they have no raw data, relocation information, or line-number entries. This
is because the .bss and .usect directives simply reserve space for uninitialized
data; uninitialized sections contain no actual code.
file header
.text
section header
.data
section header
section headers
.bss
section header
<named> section
section header
.text
raw data
.data
raw data raw data
<named> section
raw data
.text
relocation information
.data relocation
relocation information information
<named> section
relocation information
.text
line numbers
.data line-number
line numbers entries
<named> section
line numbers
symbol table
string table
The C54x development tools can detect the difference in the file headers and
automatically compensate for it. This is true if using only C54x development
tools.
To tell the difference between COFF files, you can look at the magic number
in the optional file header. Bytes 0 and 1 contain the magic number. For the
SunOSt or HP-UXt operating systems, the magic number is 108h. For the
DOS operating system, the magic number is 801h.
A-4
File Header Structure
4-7 Long integer Time and date stamp; indicates when the file
was created
16-17 Unsigned short integer Number of bytes in the optional header. This
field is either 0 or 28; if it is 0, then there is no
optional file header
20-21 Unsigned short integer Target ID; magic number indicates the file
can be executed in a TMS320C54xt
system
Table A-2 lists the flags that can appear in bytes 18 and 19 of the file header.
Any number and combination of these flags can be set at the same time (for
example, if bytes 18 and 19 are set to 0003h, F_RELFLG and F_EXEC are
both set.)
A-6
Section Header Structure
For COFF2, section names that are longer than eight characters are stored in
the string table. The field in the symbol table entry that would normally contain
the symbol’s name contains, instead, a pointer to the symbol’s name in the
string table.
Table A-6 lists the flags that can appear in the section header. The flags can
be combined. For example, if the flag’s word is set to 024h, both
STYP_GROUP and STYP_TEXT are set.
A-8
Section Header Structure
STYP_COPY 0010h Copy section (relocated, loaded, but not allocated; relo-
cation and line-number entries are processed normally)
Note: The term loaded means that the raw data for this section appears in the object file.
36 and 37 COFF1
40 to 43 COFF2
Figure A-3 illustrates how the pointers in a section header would point to the
elements in an object file that are associated with the .text section.
.text 0-7 8-1 1 12-15 16-19 20-23 24-27 28-31 32-33 34-35 36-37 38 39
Section
Header .text • • •
.text
raw data
.text
relocation information
.text
line-number entries
As Figure A-2 on page A-3 shows, uninitialized sections (created with the
.bss and .usect directives) vary from this format. Although uninitialized
sections have section headers, they have no raw data, relocation information,
or line-number information. They occupy no actual space in the object file.
Therefore, the number of relocation entries, the number of line-number en-
tries, and the file pointers are 0 for an uninitialized section. The header of an
uninitialized section simply tells the linker how much space for variables it
should reserve in the memory map.
A-10
Structuring Relocation Information
COFF file relocation information entries use the 12-byte format shown in
Table A-7.
The virtual address is the symbol’s address in the current section before relo-
cation; it specifies where a relocation must occur. (This is the address of the
field in the object code that must be patched.)
The symbol table index is the index of the referenced symbol. In the
preceding example, this field would contain the index of X in the symbol table.
The amount of the relocation is the difference between the symbol’s current
address in the section and its assembly-time address. The relocatable field
must be relocated by the same amount as the referenced symbol. In the
example, X has a value of 0 before relocation. Suppose X is relocated to
address 2000h. This is the relocation amount (2000h - 0 = 2000h), so the
relocation field at address 1 is patched by adding 2000h to it.
You can determine a symbol’s relocated address if you know which section it
is defined in. For example, if X is defined in .data and .data is relocated by
2000h, X is relocated by 2000h.
The relocation type specifies the size of the field to be patched and describes
how to calculate the patched value. The type field depends on the addressing
mode that was used to generate the relocatable reference. In the preceding
example, the actual address of the referenced symbol (X) will be placed in a
16-bit field in the object code. This is a 16-bit direct relocation, so the relocation
type is R_RELWORD. Table A-8 lists the relocation types.
A-12
Line-Number Table Structure
Byte
Number Type Description
0-3 Long integer This entry may have one of two values:
1) If it is the first entry in a block of line-number entries,
it points to a symbol entry in the symbol table.
2) If it is not the first entry in a block, it is the physical ad-
dress of the line indicated by bytes 4-5.
Figure A-4 shows how line-number entries are grouped into blocks.
Symbol Index 1 0
physical address line number
physical address line number
Symbol Index n 0
physical address line number
physical address line number
- For the first line of a function, bytes 0-3 point to the name of a symbol or
a function in the symbol table, and bytes 4-5 contain a 0, which indicates
the beginning of a block.
- For the remaining lines in a function, bytes 0-3 show the physical address
(the number of words created by a line of C/C++ source) and bytes 4-5
show the address of the original C/C++ source, relative to its appearance
in the C/C++ source program.
• 0
0 1
4 2 line-number
entries
7 3
(Note that the symbol table entry for XYZ has a field that points back to the
beginning of the line-number block.)
Because line numbers are not often needed, the linker provides an option (-s)
that strips line-number information from the object file; this provides a more
compact object module.
A-14
Symbol Table Structure and Content
filename 1
function 1
local symbols
for function 1
function 2
local symbols for
function 2
filename 2
function 1
local symbols
for function 1
static variables
Static variables refer to symbols defined in C/C++ that have storage class
static outside any function. If you have several modules that use symbols with
the same name, making them static confines the scope of each symbol to the
module that defines it (this eliminates multiple-definition conflicts).
The entry for each symbol in the symbol table contains the symbol’s:
- Name (or a pointer into the string table)
- Type
- Value
- Section it was defined in
- Storage class
- Basic type (integer, character, etc.)
- Derived type (array, structure, etc.)
- Dimensions
- Line number of the source code that defined the symbol
All symbol entries, regardless of class and type, have the same format in the
symbol table. Each symbol table entry contains the 18 bytes of information
listed in Table A-10. Each symbol may also have an 18-byte auxiliary entry;
the special symbols listed in Table A-1 1 on page A-17 always have an auxiliary
entry. Some symbols may not have all the characteristics listed above; if a par-
ticular field is not set, it is set to null.
A-16
Symbol Table Structure and Content
Symbol Description
.file File name
etext Next available address after the end of the .text output section
edata Next available address after the end of the .data output section
end Next available address after the end of the .bss output section
- nfake/.eos name and define the limits of structures, unions, and enumera-
tions that were not named. The .eos symbol is also paired with named
structures, unions, and enumerations.
When a structure, union, or enumeration has no tag name, the compiler
assigns it a name so that it can be entered into the symbol table. These names
are of the form nfake, where n is an integer. The compiler begins numbering
these symbol names at 0.
Symbol Table
Block 1: .bb
symbols for
block 1
.eb
Block 2: .bb
symbols for
block 2
.eb
function name
.bf
symbols for
the function
.ef
If a function returns a structure or union, a symbol table entry for the special
symbol .target will appear between the entries for the function name and the
.bf special symbol.
A-18
Symbol Table Structure and Content
- If the symbol name is greater than 8 characters, this field is treated as two
long integers. The entire symbol name is stored in the string table. Bytes
0-3 contain 0, and bytes 4-7 are an offset into the string table.
The address of the string table is computed from the address of the symbol
table and the number of symbol table entries.
Figure A-9 is a string table that contains two symbol names, Adaptive-Filter
and Fourier-Transform. The index in the string table is 4 for Adaptive-Filter and
20 for Fourier-Transform.
38
‘A’ ‘d’ ‘a’ ‘p’
‘t’ ‘i’ ‘v’ ‘e’
‘-’ ‘F’ ‘i’ ‘l’
‘t’ ‘e’ ‘r’ ‘\0’
‘F’ ‘o’ ‘u’ ‘r’
‘i’ ‘e’ ‘r’ ‘-’
‘T’ ‘r’ ‘a’ ‘n’
‘s’ ‘f’ ‘o’ ‘r’
‘m’ ‘\0’
C_STRTAG 10 Structure tag C_FILE 103 Filename; used only for the
.file special symbol
Some special symbols are restricted to certain storage classes. Table A-13
lists these symbols and their storage classes.
A-20
Symbol Table Structure and Content
.ef C_FCN
If a symbol’s storage class is C_FILE, the symbol’s value is a pointer to the next
.file symbol. Thus, the .file symbols form a one-way linked list in the symbol
table. When there are no more .file symbols, the final .file symbol points back
to the first .file symbol in the symbol table.
The value of a relocatable symbol is its virtual address. When the linker
relocates a section, the value of a relocatable symbol changes accordingly.
If there were no .text, .data, or .bss sections, the numbering of named sections
would begin with 1.
If a symbol has a section number of 0, -1, or -2, it is not defined in a section.
A section number of -2 indicates a symbolic debugging symbol, which
includes structure, union, and enumeration tag names; type definitions; and
the filename. A section number of -1 indicates that the symbol has a value but
is not relocatable. A section number of 0 indicates a relocatable external
symbol that is not defined in the current file.
Bits 0-3 of the type field indicate the basic type. Table A-16 lists valid basic
types.
A-22
Symbol Table Structure and Content
Bits 4-15 of the type field are arranged as six 2-bit fields that can indicate one
to six derived types. Table A-17 lists the possible derived types.
DT_PTR 1 Pointer
DT_FCN 2 Function
DT_ARY 3 Array
Each symbol table entry may have one or no auxiliary entry. An auxiliary sym-
bol table entry contains the same number of bytes as a symbol table entry (18),
but the format of an auxiliary entry depends on the symbol’s type and storage
class. Table A-18 summarizes these relationships.
Type Entry
Storage Derived Basic
Name Class Type 1 Type Auxiliary Entry Format
.file C_FILE DT_NON T_NULL Filename (see Table A-19)
.text, .data, .bss C_STAT DT_NON T_NULL Section (see Table A-20)
arrname (See note 2) DT_ARY (See note 1) Array (see Table A-24)
.bb, .eb C_BLOCK DT_NON T_VOID Beginning and end of a block (see
Table A-25 and Table A-26)
.bf, .ef C_FCN DT_NON T_VOID Beginning and end of a function (see
Table A-25 and Table A-26)
Name related to a (See note 2) DT_PTR T_STRUCT Name related to a structure, union, or
structure, union, or DT_ARR T_UNION enumeration (see Table A-27)
enumeration DT_NON T_ENUM
In Table A-18, tagname refers to any symbol name (including the special
symbol nfake). Fcname and arrname refer to any symbol name.
A symbol that satisfies more than one condition in Table A-18 should have a
union format in its auxiliary entry. A symbol that satisfies none of these condi-
tions should not have an auxiliary entry.
A-24
Symbol Table Structure and Content
A.7.8.1 Filenames
Each of the auxiliary table entries for a filename contains a 14-character file-
name in bytes 0-13. Bytes 14-17 are unused.
14-17 — Unused
A.7.8.2 Sections
Table A-21 illustrates the format of auxiliary table entries for tag names.
Table A-22 illustrates the format of auxiliary table entries for ends of
structures.
A.7.8.5 Functions
Table A-23 illustrates the format of auxiliary table entries for functions.
A-26
Symbol Table Structure and Content
A.7.8.6 Arrays
Table A-24 illustrates the format of auxiliary table entries for arrays. Note that
multi-dimensional arrays are limited to 4 dimensions. This limitation can be
avoided by using DWARF format (compile with the -gw shell option).
Table A-25 illustrates the format of auxiliary table entries for the ends of blocks
and functions.
Table A-26 illustrates the format of auxiliary table entries for the beginnings
of blocks and functions.
Table A-27 illustrates the format of auxiliary table entries for the names of
structures, unions, and enumerations.
Table A-27. Structure, Union, and Enumeration Names Format for Auxiliary Table Entries
Byte
Number Type Description
0-3 Long integer Tag index
A-28
Appendix
AppendixBA
- The .func and .endfunc directives specify the beginning and ending lines
of a C/C++ function.
- The .block and .endblock directives specify the bounds of C/C++ blocks.
- The .file directive defines a symbol in the symbol table that identifies the
current source file name.
- The .line directive identifies the line number of a C/C++ source statement.
These symbolic debugging directives are not usually listed in the assembly
language file that the compiler creates. If you want them to be listed, invoke
the compiler shell with the -g option, as shown below:
cl500 -g input file
B-1
Define a Block .block/.endblock
Syntax
.block beginning line number
.endblock ending line number
Description The .block and .endblock directives specify the beginning and end of a
C/C++ block. The line numbers are optional; they specify the location in the
source file where the block is defined.
Block definitions can be nested. The assembler will detect improper block
nesting.
Example Following is an example of C source that defines a block, and the resulting
assembly language code.
C source:
.
.
.
{ /* Beginning of a block */
int a,b;
a = b;
} /* End of a block */
.
.
.
.block 8
.sym _a,2,4,1,16
.sym _b,3,4,1,16
.line 9
LD *SP(3),A ; cycle 3
STL A,*SP(2) ; cycle 4
.endblock 10
Syntax
.file ”filename”
Description The .file directive allows a debugger to map locations in memory back to lines
in a C/C++ source file. The filename is the name of the file that contains the
original C/C++ source program. The first 14 characters of the filename are sig-
nificant.
You can also use the .file directive in assembly code to provide a name in the
file and improve program readability.
Example In the following example, the filename text.c contained the C source that pro-
duced this directive.
.file ”text.c”
B-4
Define a Function .func/.endfunc
Syntax
.func beginning line number
.endfunc ending line number
Description The .func and .endfunc directives specify the beginning and end of a C/C++
function. The line numbers are optional; they specify the location in the source
file where the function is defined. Function definitions cannot be nested.
Example Following is an example of C source that defines a function, and the resulting
assembly language code:
C source:
power(x, n) /* Beginning of a function */
int x,n;
{
int i, p;
p = 1;
for (i = 1; i <= n; ++i)
p = p * x;
return p; /* End of function */
}
B-6
Create a Line Number Entry .line
Syntax
.line line number [, address]
Description The .line directive creates a line number entry in the object file. Line number
entries are used in symbolic debugging to associate addresses in the object
code with the lines in the source code that generated them.
- The line number indicates the line of the C/C++ source that generated a
portion of code. Line numbers are relative to the beginning of the current
function. This is a required parameter.
- The address is an expression that is the address associated with the line
number. This is an optional parameter; if you don’t specify an address, the
assembler will use the current SPC value.
Example The .line directive is followed by the assembly language source statements
that are generated by the indicated line of C source. For example, assume that
the lines of C source below are line 4 and 5 in the original C source; line 5
produces the assembly language source statements that are shown below.
C source:
for (i = 1; i <= n; ++i)
p = p * x;
Resulting assembly language code:
31 .line 7
32 00000d 4400 LD *SP(0),16,A ; cycle 1
33 00000e 3102 MPYA *SP(2) ; cycle 2
34 00000f 8102 STL B,*SP(2) ; cycle 3
35 .line 6
36 000010 6b01 ADDM #1,*SP(1) ; cycle 4
000011 0001
37 000012 f7b8 SSBX SXM ; cycle 6
38 000013 f495 nop
39 000014 1004 LD *SP(4),A ; cycle 8
40 000015 0801 SUB *SP(1),A ; cycle 9
41 000016 f842 BC L2,AGEQ ; cycle 10
000017 000d’
42 ; branch occurs ; cycle 15
43 000018 L3:
44 .line 8
45 000018 1002 LD *SP(2),A
46 .line 9
47 000019 ee03 FRAME #3 ; cycle 1
48 00001a fc00 RET ; cycle 2
49 ; branch occurs ; cycle 7
50 .endfunc 9,000000000h,3
Syntax
.member name, value [, type, storage class, size, tag, dims]
B-8
Define a Structure .stag/.etag/.utag/.eos
Syntax
.stag name [, size]
member definitions
.eos
.etag name [, size]
member definitions
.eos
.utag name [, size]
member definitions
.eos
Description The .stag directive begins a structure definition. The .etag directive begins an
enumeration definition. The .utag directive begins a union definition. The .eos
directive ends a structure, enumeration, or union definition.
C source:
struct doc
{
char title;
char group;
int job_number;
} doc_info;
C source:
union u_tag {
int val1;
float val2;
char valc;
} valu;
C Source:
{
enum o_ty { reg_1, reg_2, result } optypes;
}
B-10
Define a Symbol .sym
Syntax
.sym name, value [, type, storage class, size, tag, dims]
Description The .sym directive specifies symbolic debug information about a global vari-
able, local variable, or a function.
- Name is the name of the variable that is put in the object symbol table. The
first 32 characters of the name are significant.
- Value is the value associated with the variable. Any legal expression
(absolute or relocatable) is acceptable.
- Type is the C/C++ type of the variable. Appendix A, Common Object File
Format, contains more information about C/C++ types.
- Storage class is the C/C++ storage class of the variable. Appendix A,
Common Object File Format, contains more information about C/C++
storage classes.
- Size is the number of bits of memory required to contain this variable.
- Tag is the name of the type (if any) or structure of which this variable is a
type. This name must have been previously declared by a .stag, .etag, or
.utag directive.
- Dims may be up to four expressions separated by commas. This allows
up to four dimensions to be specified for the variable.
The order of parameters is significant. The name and value are required
parameters. All other parameters may be omitted or empty (adjacent commas
indicate an empty entry). This allows you to skip a parameter and specify a
parameter that occurs later in the list. Operands that are omitted or empty
assume a null value.
Example These lines of C source produce the .sym directives shown below:
C source:
struct s { int member1, member2; } str;
int ext;
int array[5][10];
long *ptr;
int strcmp();
main(arg1,arg2)
int arg1;
char *arg2;
{
register r1;
}
B-12
Appendix
AppendixCA
The flexible hex conversion utility offers many options and capabilities. Once
you understand the proper ways to configure the EPROM system and the
requirements of the EPROM programmer, you will find that converting a file for
a specific application is easy.
Topic Page
C-1
Base Code for the Examples
**********************************************************
* Assemble two words into section, ”sec1” *
**********************************************************
.sect ”sec1”
.word 1234h
.word 5678h
**********************************************************
* Assemble two words into section, ”sec2” *
**********************************************************
.sect ”sec2”
.word 0aabbh
.word 0ccddh
.end
C-2
Example 1: Building A Hex Command File for Two 8-Bit EPROMs
C.2 Example 1: Building A Hex Command File for Two 8-Bit EPROMs
Example 1 shows how to build the hex command file you need for converting
a COFF object file for the memory system shown in Figure C-1. In this system,
there are two external 64K 8-bit EPROMs interfacing with a C54x target pro-
cessor. Each of the EPROMs contributes 8 bits of a 16-bit word for the target
processor.
CPU
64K 8 64K 8
ROM0 ROM1
Width 16 Bits
ROM width ROM width
8 bits 8 bits
By default, the hex conversion utility uses the linker load address as the base
for generating addresses in the converted output file. However, for this
application, the code will reside at physical EPROM address 0x0010, rather
than the address specified by the linker (0x1400). The circuitry of the target
board handles the translation of this address space. The paddr parameter allo-
cates a section and burns the code at EPROM address 0x0010.
The paddr parameter is specified within the SECTIONS directive (see Section
10.6, The SECTIONS Directive, on page 10-22 for details). If you use the
paddr parameter to specify a load address for one section included in the con-
version, then you must specify a paddr for each section included in the conver-
sion. When setting the paddr parameter, you must ensure that the specified
addresses do not overlap the linker-assigned load addresses of sections that
follow.
In Example 1, two sections are defined: sec1 and sec2. You can easily add a
paddr parameter for each of these sections from within the SECTIONS direc-
tive. However, the task may become unmanageable for large applications with
many sections, or in cases where section sizes may change often during code
development.
To work around this problem, you can combine the sections at link stage, creat-
ing a single section for conversion. To do this, use the linker command shown
in Example C-2.
test.obj
-o test.out
-m test.map
MEMORY
{
PAGE 0 : EXT_PRG : org = 0x1400 , len = 0xEB80
}
SECTIONS
{
outsec: { *(sec1)
*(sec2) } > EXT_PRG PAGE 0
}
The EPROM programmer in this example has the following system require-
ments:
- The hex conversion utility must locate code starting at EPROM address
0x0010.
Option Description
-i Create Intel format
C-4
Example 1: Building A Hex Command File for Two 8-Bit EPROMs
With the memory width and ROM width values above, the utility will automati-
cally generate two output files. The ratio of memory width to ROM width deter-
mines the number of output files. The ROM0 file contains the lower 8 of the 16
bits of raw data, and the ROM1 file contains the upper 8 bits of the correspond-
ing data.
Example C-3 shows the hex command file with all of the selected options.
Figure C-2 (a) shows the contents of the converted file for ROM0 (low8.bit)
containing the lower 8 bits. Figure C-2 (b) shows the contents of the converted
file for ROM1 (upp8.bit) containing the upper 8 bits of data.
0x0010 34
78
BB
DD
0x0010 12
56
AA
CC
C-6
Example 1: Building A Hex Command File for Two 8-Bit EPROMs
To illustrate precisely how the utility performs the conversion, specify the -map
option. Although not required, the -map option generates useful information
about the output. The resulting map is shown in Example C-4.
Example C-4. Map File Resulting From Hex Command File in Example C-3 on page C-5
******************************************************
TMS320C54x COFF/Hex Converter Version x.xx
******************************************************
Fri Oct 11 15:10:53 2001
- Link the sections together into one output section for conversion.
Example C-6 (a) shows a linker command file for this method. The linker
should be executed with this command file; then, the hex conversion utility
should be executed with the set of commands shown in Example C-6 (b).
MEMORY
{
PAGE 0: DARAM: org = 0x0080 , length = 0x1370
EXT: org = 0x1400 , length = 0xEB80
}
SECTIONS
{
sec1 : load = EXT PAGE 0
sec2 : load = EXT PAGE 0
}
C-8
Example 2: Avoiding Holes With Multiple Sections
-i
test.out
-map example.mxp
ROMS
{
PAGE 0: ROM: org = 0x0000, length = 0x800, romwidth = 8, memwidth = 8
}
SECTIONS
{
sec1: paddr = 0x0000
sec2: paddr = 0x0004
}
-i
test.out
-map example.mxp
ROMS
{
PAGE 0: ROM : org = 0x0100, length = 0x0800, romwidth = 8, memwidth = 8,
files = {examp2_2.hex}
}
SECTIONS
{
outsec: paddr = 0x100
}
int array[]={1,2,3,4};
main()
{
array[0] = 5;
}
Figure C-3 shows the EPROM memory system for which the output file will be
generated. In this application, the single C54x device is booted from a 128K
8-bit EPROM. The requirement of the system is that the boot table must
reside at EPROM memory address 0.
CPU
C54x
128K 8
ROM0
Width 16 bits
ROM width
8 bits
C-10
Example 3: Generating a Boot Table
The on-chip boot loader loads only a single block. This may present a problem
when you are loading C code compiled with the TMS320C54x C compiler. The
TMS320C54x C compiler creates several sections or blocks when it compiles
C source code. Some applications may require that all sections associated
with the program be included in the boot to have a complete executable
program. In this case, the individual sections must be combined into a single
section for boot.
The hex conversion utility does not combine individual sections; therefore, you
must use the linker to group those sections.
The sections that the compiler creates are divided into two categories: initial-
ized sections (sections that contain data or code) and uninitialized sections
(sections that reserve space but contain no actual data). Initialized sections
created by the TMS320C54x C compiler include .text, .cinit, .const, and .data.
Uninitialized sections are ignored by the hex conversion utility and are not
converted.
Most applications require that .text and .cinit sections are included in the boot.
This allows code and information for the C boot routine (c_int00 defined in
boot.asm) to load and run, initializing the C environment and branching to the
main function in the applications code.
The .text and .cinit sections must be linked together as a single section in the
linker command file. The .cinit section contains the initialization data and
tables for all global or static C symbols that were declared with an initial value
(i.e. int x = 5; ). Note that the linker handles the .cinit section differently than
the other sections.
This last word contains a zero that is used to mark the end of the initialization
table. However, if .cinit is included as an input section only, the linker sets cinit
to -1, indicating that no initialization tables were loaded. Therefore, the C boot
routine, c_int00, does not attempt to initialize any of the global or static C
symbols.
When linking the .cinit section into an output section other than .cinit, the linker
does not perform the automatic functions listed above. Therefore, these func-
tions must be implemented explicitly within the linker command file.
Example C-8 shows a linker command file that places .text and .cinit into a
single output section named boot_sec.
-c
-l rts.lib
-m boot1.map
-o boot.out
MEMORY
{
PAGE 0 : PROG : origin = 001400h, length = 01000h
PAGE 1 : DATA : origin = 0080h, length = 01000h
}
SECTIONS
{
boot_sec: { *(.text)
/*-------------------------------------*/
/* Set start address for C init table */
/*-------------------------------------*/
cinit = .;
/*-------------------------------------*/
/* Include all cinit sections */
/*-------------------------------------*/
*(.cinit)
/*-------------------------------------*/
/* Reserve a single space for the zero */
/* word to mark end of C init */
/*-------------------------------------*/
.+=1;
}
fill = 0x0000, /* Make sure fill value is 0 */
load = PROG PAGE 0
.data : {} > DATA PAGE 1
.bss : {} > DATA PAGE 1
.const : {} > DATA PAGE 1
.sysmem : {} > DATA PAGE 1
.stack : {} > DATA PAGE 1
}
Example C-9 shows a portion of the map file generated when the linker is
executed with this command file.
C-12
Example 3: Generating a Boot Table
Example C-9. Section Allocation Portion of Map File Resulting From the Command File
[12 symbols]
Notice that the linker placed a hole at the end of the section boot_sec with a
fill value of 0, as specified in the command file. Also, the global symbol cinit
coincides with the start of the first .cinit section included in the link. When the
linker is executed with the command file in Example C-8 on page C-12, the
linker issues warnings that the output file contains no .text section and that the
global symbol cinit is being redefined. These warnings may be ignored in this
instance.
Executing the linker with the command file in Example C-8 on page C-12
yields a COFF file that can be used as input to the hex conversion utility to build
the desired boot table.
The hex conversion utility has options that describe the requirements for the
EPROM programmer and options that describe the EPROM memory system.
For Example 3, assume that the EPROM programmer has only one require-
ment: that the hex file be in Intel format.
In the EPROM memory system illustrated in Figure C-3 on page C-10, the
EPROM system memory width is 8 bits, and the physical ROM width is 8 bits.
You must set the following options in the hex command file to reflect the
requirements of the system:
Option Description
-i Create Intel format.
Because the application requires the building of a boot table for parallel boot
mode, you must set the following options in the hex command file to reflect the
requirements of the system:
Option Description
-boot Create a boot load table.
C-14
Example 3: Generating a Boot Table
-map boot2.map
ROMS
{
PAGE 0 : ROM : origin = 0x0000, length = 0x20000
}
In Example 3, memory width and ROM width are the same; therefore, the hex
conversion utility creates a single output file. The number of output files is
determined by the ratio of memwidth to romwidth.
Example C-11 shows the map file boot2.map, resulting from executing the
command file in Example C-10, which includes the -map option.
Example C-11. Map File Resulting From the Command File in Example C-10
******************************************************
TMS320C54x COFF/Hex Converter Version x.xx
******************************************************
Fri Oct 11 15:27:46 2001
INPUT FILE NAME: <boot.out>
OUTPUT FORMAT: Intel
PHYSICAL MEMORY PARAMETERS
Default data width: 16
Default memory width: 8 (MS-->LS)
Default output width: 8
BOOT LOADER PARAMETERS
The hex conversion utility output file boot.hex, resulting from the command file
in Example C-10, is shown in Example C-12.
Example C-12. Hex Conversion Utility Output File Resulting From the Command File in
Example C-10
:200000001400007976F800800005FC00771800A66BF8001803FF68F80018FFFEF7B8F7BED9
:20002000F4A0F6B7F6B5F6B6F020146DF1000001F84D142BF07314257EF80012F00000010C
:2000400047F800117E9200F80011F00000017EF80011F00000016C89141AF0741400F074CF
:2000600014674A117211008410F80011FA4514444A16EEFF4811F00000868816F495F49527
:2000800010EEFFFFF4E36CE9FFFF143E10F80085F845144B10F80085F4E3F495F073144C0F
:2000A000F7B811F80084F3100020FA4B145BF4954A11F2731465F495E80172110084491198
:2000C00080E10086F3000001E80081F800848A11FC00EEFFE801F074142FEE01FC0000045D
:1800E00000800001000200030004000100840000000100850000000073
:00000001FF
C-16
Example 4: Generating a Boot Table for LP Core Devices
main()
{
array[0] = 5;
}
Note that this example is compiled with the -v548 compiler option.
Figure C-4 shows the EPROM memory system for which the output file will be
generated. In this application, the single C54xLP device is booted from a 128K
8-bit EPROM. The requirements of the system are that the boot table must
reside at EPROM memory address 0.
CPU
’C54xLP
128K 8
ROM0
Width 16 bits
ROM width
8 bits
The sections that the compiler creates are divided into two categories: initial-
ized sections (sections that contain data or code) and uninitialized sections
(sections that reserve space but contain no actual data). Initialized sections
created by the TMS320C54x C compiler include .text, .cinit, .const, and .data.
Uninitialized sections are ignored by the hex conversion utility and are not
converted.
Most applications require that .text and .cinit sections are included in the boot.
This allows code and information for the C boot routine (c_int00 defined in
boot.asm) to load and run, initializing the C environment and branching to the
main function in the applications code.
The .cinit section contains the initialization data and tables for all global or
static C symbols that were declared with an initial value (i.e. int x = 5; ). Note
that the linker handles the .cinit section differently than the other sections.
This last word contains a zero that is used to mark the end of the initialization
table. However, if .cinit is included as an input section only, the linker sets cinit
to -1, indicating that no initialization tables were loaded. Therefore, the C boot
routine, c_int00, does not attempt to initialize any of the global or static C
symbols.
When linking the .cinit section into an output section other than .cinit, the linker
does not perform the automatic functions listed above. Therefore, these func-
tions must be implemented explicitly within the linker command file.
C-18
Example 4: Generating a Boot Table for LP Core Devices
-c
c54xlp.obj
-l rts.lib
-m c54xlp.map
-o c54xlp.out
MEMORY
{
PAGE 0 : PROG : origin = 001400h, length = 01000h
PAGE 1 : DATA : origin = 0080h, length = 01000h
}
SECTIONS
{
.text : {} > PROG PAGE 0
.cinit : {} > PROG PAGE 0
.data : {} > DATA PAGE 1
.bss : {} > DATA PAGE 1
.const : {} > DATA PAGE 1
.sysmem : {} > DATA PAGE 1
.stack : {} > DATA PAGE 1
}
Example C-15 shows the map file generated when the linker is executed with
the command file in Example C-14. Linking with this command file creates a
COFF file you use as input to the hex conversion utility to build the desired boot
table.
Example C-15. Section Allocation Portion of Map File Resulting From the Command File
in Example C-14
MEMORY CONFIGURATION
Example C-15. Section Allocation Portion of Map File Resulting From the Command File
in Example C-14 (Continued)
output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.text 0 00001400 0000006d
00001400 00000004 c54xlp.obj (.text)
00001404 0000002b rts.lib : boot.obj (.text)
0000142f 0000003e : exit.obj (.text)
.cinit 0 0000146d 0000000d
0000146d 00000006 c54xlp.obj (.cinit)
00001473 00000006 rts.lib : exit.obj (.cinit)
00001479 00000001 --HOLE-- [fill = 0000]
.data 1 00000080 00000000 UNINITIALIZED
00000080 00000000 c54xlp.obj (.data)
00000080 00000000 rts.lib : exit.obj (.data)
00000080 00000000 : boot.obj (.data)
.bss 1 00000080 00000026 UNINITIALIZED
00000080 00000004 c54xlp.obj (.bss)
00000084 00000000 rts.lib : boot.obj (.bss)
00000084 00000022 : exit.obj (.bss)
.const 1 00000080 00000000 UNINITIALIZED
.sysmem 1 00000080 00000000 UNINITIALIZED
.stack 1 000000a6 00000400 UNINITIALIZED
000000a6 00000000 rts.lib : boot.obj (.stack)
GLOBAL SYMBOLS
[18 symbols]
C-20
Example 4: Generating a Boot Table for LP Core Devices
The hex conversion utility has options that describe the requirements for the
EPROM programmer and options that describe the EPROM memory system.
For Example 4, assume that the EPROM programmer has only one require-
ment: that the hex file be in Intel format.
In the EPROM memory system illustrated in Figure C-4 on page C-17, the
EPROM system memory width is 8 bits and the physical ROM width is 8 bits.
The following options are selected to reflect the requirements of the system:
Option Description
-i Create Intel format.
Because the application requires the building of a boot table for parallel boot
mode, the following options must be selected as well:
Option Description
-boot Create a boot load table.
ROMS
{
PAGE 0 : ROM : origin = 0x0000, length = 0x20000
}
In Example 4, memory width and ROM width are the same; therefore, the hex
conversion utility creates a single output file. The number of output files is
determined by the ratio of memwidth to romwidth.
Example C-17 shows the map file c54xlp.mxp, resulting from executing the
command file in Example C-16, which includes the -map option.
C-22
Example 4: Generating a Boot Table for LP Core Devices
Example C-17. Map File Resulting From the Command File in Example C-16
******************************************************
TMS320C54x COFF/Hex Converter Version x.xx
******************************************************
Sat Sep 21 17:01:13 2001
The hex conversion utility output file c54xlp.hex, resulting from the command
file in Example C-16, is shown in Example C-18.
Example C-18. Hex Conversion Utility Output File Resulting From the Command File in
Example C-16
:2000000008AA7FFFF800FFFFFFFF00870000140076F800800005FE00E800F495771800A68A
:200020006BF8001803FF68F80018FFFEF7B8F7BEF6B9F4A0F6B7F6B5F6B6F0201487F10087
:200040000001F84D1430F273142AF6B8F4957EF80012F000000147F800117E9200F800115A
:20006000F00000017EF80011F00000016C89141FF7B8EEFCF020FFFFF1000001F84D1444B9
:20008000F273143E4E02F495F5E356027E001100FA4C143C6B030001F6B8EE04F0741400F4
:2000A000F074144A4A114A16721100A410F80011FA451460F495EEFF4811F00000848816EF
:2000C000F495F49510EEFFFFF4E36CE9FFFF145A10F800A5F845146710F800A5F4E3F0742D
:2000E0001484EE018A168A11FC00F7B8E9204A1109F800A4F84E1478F2731482F495E8014B
:1E010000721100A4491180E10084F3000001E80081F800A48A11FC00F495F073148566
:20011E00000D00001487000400800001000200030004000100A40000000100A50000000040
:02013E000000BF
:00000001FF
Assembler&Error Messages
When the assembler completes its second pass, it reports any errors that it
encountered during the assembly. It also prints these errors in the listing file
(if one is created). An error is printed following the source line that incurred it.
You should attempt to correct the first error that occurs in your code first. A
single error condition can cause a cascade of spurious errors.
If you have received an assembler error message, use this appendix to find
possible solutions to the problem you encountered. First, locate the error
message class number. Then, locate the error message that you encountered
within that class. Each class number has an alphabetical list of error messages
that are associated with it. Each class has a Description of the problem and
an Action that suggests possible remedies.
D-1
E0000
D-2
E0002
E0003
D-4
E0004
Absolute, well-defined integer value expected
Expecting accumulator A or B
Expecting ASM or shift value
Expecting dual memory addressing
Identifier expected
Identifier operand expected
Illegal character argument specified
Illegal combination of Smem operands
Illegal floating-point expression
Illegal operand
Illegal shift operation
Illegal structure reference
Incorrect bit symbol for specified status register
Invalid data size for relocation
Invalid float constant specified
Invalid identifier, sym, specified
Invalid macro parameter specified
Invalid operand, ”char”
Must add to the destination operand
No parameters available for macro arguments
Not expecting direct operand op
Not expecting immediate value operand op
Not expecting indirect operand op
Offset Addressing modes not legal for MMR addressing
Operand must be auxiliary register or SP
Operand must be auxiliary register
Operand must be T
Register must be ARn or SP
Single character operand expected
String constant or substitution symbol expected
String operand expected
Structure/Union tag symbol expected
Substitution symbol operand expected
The accumulator operands must be different
The operands must be SP
Description These errors are about illegal operands. The instruction,
parameter or other operand specified was not legal for this
syntax.
Action Correct the source per the error message text.
E0006
.break must occur within a loop
Conditional assembly mismatch
Matching .endloop missing
No matching .if specified
No matching .endif specified
No matching .endloop specified
No matching .if specified
No matching .loop specified
Open block(s) inside macro
Unmatched .endloop directive
Unmatched .if directive
Description These are errors about unmatched conditional assembly
directives. A directive was encountered that requires a
matching directive but the assembler could not find the
matching directive.
Action Correct the source per the error message text.
E0007
Conditional nesting is too deep
Loop count out of range
Description These are errors about conditional assembly loops. Condi-
tional block nesting cannot exceed 32 levels.
Action Correct the .macro/.endmacro, .if/.elseif/.else/.endif or .loop/
.break/.endloop source.
D-6
E0008
E0009
E0100
Label missing
Label required
.setsym requires a label
Description These are errors about required labels. The given directive
requires a label, but none is specified.
Action Correct the source by specifying the required label.
D-8
E0102
E0200
E0300
D-10
E0301
E0400
E0500
E0501
E0600
E0700
D-12
E0800
E0801
Action Check the source for parallel instruction problems and correct
per the error message text.
E0900
E1000
D-14
E1300
E9999
Pass conflict
Description This is an internal assembler error. If it occurs repeatedly, the
assembler may be corrupt or confused.
Action Assemble a smaller file. If a smaller file does not assemble,
reinstall the assembler.
Ambiguous assignment
Invalid page number specified - ignored
Macro parameter conflict
No operands expected. Operands ignored
Specified alignment is outside accessible memory - ignored
Trailing operand does not exist
Trailing operands ignored
Unrecognized operand, ignored
*+ARn addressing is for write-only
Description These are warnings about operands. The assembler encoun-
tered operands that it did not expect.
Action Check the source to determine what caused the problem and
whether you need to correct the source.
D-16
W0001
W0002
W0004
W9999
D-18
Appendix
AppendixEA
Linker&Error Messages
This appendix lists the the linker error messages in alphabetical order accord-
ing to the error message. In these listings, the symbol (...) represents the name
of an object that the linker is attempting to interact with when an error occurs.
Action Check the syntax of all expressions, and check the input di-
rectives for accuracy.
E-1
alignment for (...) redefined
Description More than one alignment is supplied for a section.
B
bad fill value
Description The fill value must be a 16-bit constant.
binding address (...) for section (...) is outside all memory on page
(...)
Description Not every section falls within memory configured with the
MEMORY directive.
Action If you are using a linker command file, check that MEMORY
and SECTIONS directives allow enough room to ensure that
no sections are being placed in unconfigured memory.
E-2
blocking for (...) redefined
Description More than one blocking value is supplied for a section.
E-4
can’t open filename
Description The specified file does not exist.
Action Check spelling, pathname, environment variables, etc. The
filename must conform to operating system conventions.
E-6
fail to skip (...)
Description The file may be corrupt.
Action If the input file is corrupt, try reassembling it.
E-8
L
length redefined for memory area (...)
Description A memory area in a MEMORY directive has more than one
length.
M
-m flag does not specify a valid filename
Description You did not specify a valid filename for the file you are writing
the output map file to.
E-10
no allocation allowed with a GROUP-allocation for section (...)
ignored
Description A section in a group was specified for individual allocation.
The entire group is treated as one unit, so the group may be
aligned or bound to an address, but the sections making up
the group cannot be handled individually.
no input files
Description No COFF files were supplied. The linker cannot operate with-
out at least one input COFF file.
E-12
P
PC-relative displacement overflow at address (...) in file (...)
Description The relocation of a PC-relative jump resulted in a jump dis-
placement too large to encode in the instruction.
R
-r incompatible with -s (-s ignored)
Description Both the -r option and the -s option were used. Since the -s
option strips the relocation information and -r requests a relo-
catable object file, these options are in conflict with each oth-
er.
relocation symbol not found: index (...), section (...), file (...)
Description The input file may be corrupt.
Action If the input file is corrupt, try reassembling it.
S
section (...) at (...) overlays at address (...)
Description Two sections overlap and cannot be allocated.
Action If you are using a linker command file, check that MEMORY
and SECTIONS directives allow enough room to ensure that
no sections overlap.
statement ignored
Description There is a syntax error in an expression.
T
too few symbol names in string table for archive n
Description The archive file may be corrupt.
Action If the input file is corrupt, try recreating the archive.
E-14
too many arguments - use a command file
Description You used more than ten arguments on a command line or in
response to prompts.
E-16
Appendix
AppendixFA
Glossary
A
absolute address: An address that is permanently assigned to a
TMS320C54xt memory location.
absolute lister: A debugging tool that accepts linked files as input and
creates .abs files as output. These .abs files can be assembled to pro-
duce a listing that shows the absolute addresses of object code. Without
the tool, an absolute listing can be prepared with the use of many manual
operations.
algebraic: An instruction that the assembler translates into machine code.
alignment: A process in which the linker places an output section at an
address that falls on an n-bit boundary, where n is a power of 2. You can
specify alignment with the SECTIONS linker directive.
allocation: A process in which the linker calculates the final memory
addresses of output sections.
archive library: A collection of individual files that have been grouped into
a single file.
archiver: A software program that allows you to collect several individual
files into a single file called an archive library. The archiver also allows
you to delete, extract, or replace members of the archive library, as well
as to add new members.
ASCII: American Standard Code for Information Exchange. A standard
computer code for representing and exchanging alphanumeric informa-
tion.
assembler: A software program that creates a machine-language program
from a source file that contains assembly language instructions, direc-
tives, and macro directives. The assembler substitutes absolute opera-
tion codes for symbolic operation codes, and absolute or relocatable
addresses for symbolic addresses.
assembly-time constant: A symbol that is assigned a constant value with
the .set directive.
F-1
assignment statement: A statement that assigns a value to a variable.
autoinitialization: The process of initializing global C variables (contained
in the .cinit section) before beginning program execution.
auxiliary entry: The extra entry that a symbol may have in the symbol table
and that contains additional information about the symbol (whether it is
a filename, a section name, a function name, etc.).
B
binding: A process in which you specify a distinct address for an output sec-
tion or a symbol.
block: A set of declarations and statements that are grouped together with
braces.
.bss: One of the default COFF sections. You can use the .bss directive to
reserve a specified amount of space in the memory map that can later
be used for storing data. The .bss section is uninitialized.
C
C compiler: A program that translates C source statements into assembly
language source statements.
COFF: Common object file format. A binary object file format that promotes
modular programming by supporting the concept of sections.
command file: A file that contains options, filenames, directives, or com-
ments for the linker or hex conversion utility.
comment: A source statement (or portion of a source statement) that is
used to document or improve readability of a source file. Comments are
not compiled, assembled, or linked; they have no effect on the object file.
common object file format: See COFF.
conditional processing: A method of processing one block of source code
or an alternate block of source code, according to the evaluation of a
specified expression.
configured memory: Memory that the linker has specified for allocation.
constant: A numeric value that can be used as an operand.
cross-reference listing: An output file created by the assembler that lists
the symbols that were defined, what line they were defined on, which
lines referenced them, and their final values.
F-2
D
.data: One of the default COFF sections. The .data section is an initialized
section that contains initialized data. You can use the .data directive to
assemble code into the .data section.
E
emulator: A hardware development system that emulates TMS320C54x
operation.
executable module: An object file that has been linked and can be
executed in a TMS320C54x system.
external symbol: A symbol that is used in the current program module but
is defined in a different program module.
F
field: For the TMS320C54x, a software-configurable data type whose length
can be programmed to be any value in the range of 1-16 bits.
file header: A portion of a COFF object file that contains general information
about the object file (such as the number of section headers, the type of
system the object file can be downloaded to, the number of symbols in
the symbol table, and the symbol table’s starting address).
G
global: A kind of symbol that is either 1) defined in the current module and
accessed in another, or 2) accessed in the current module but defined
in another.
Glossary F-3
H
hex conversion utility: A program that accepts COFF files and converts
them into one of several standard ASCII hexadecimal formats suitable
for loading into an EPROM programmer.
hole: An area between the input sections that compose an output section
that contains no actual code or data.
I
incremental linking: Linking files that will be linked in several passes. Often
this means a very large file that will have sections linked and then will
have the sections linked together.
input section: A section from an object file that will be linked into an
executable module.
L
label: A symbol that begins in column 1 of a source statement and corre-
sponds to the address of that statement.
linker: A software tool that combines object files to form an object module
that can be allocated into TMS320C54x system memory and executed
by the device.
listing file: An output file, created by the assembler, that lists source state-
ments, their line numbers, and their effects on the SPC.
F-4
M
macro: A user-defined routine that can be used as an instruction.
macro definition: A block of source statements that define the name and
the code that make up a macro.
macro expansion: The source statements that are substituted for the
macro call and are subsequently assembled.
magic number: A COFF file header entry that identifies an object file as a
module that can be executed by the TMS320C54x.
map file: An output file, created by the linker, that shows the memory
configuration, section composition, and section allocation, as well as
symbols and the addresses at which they were defined.
N
named section: An initialized section that is defined with a .sect directive.
O
object file: A file that has been assembled or linked and contains machine-
language object code.
object format converter: A program that converts COFF object files into
Intel format or Tektronix format object files.
Glossary F-5
object library: An archive library made up of individual object files.
optional header: A portion of a COFF object file that the linker uses to
perform relocation at download time.
output module: A linked, executable object file that can be downloaded and
executed on a target system.
overlay page: A section of physical memory that is mapped into the same
address range as another section of memory. A hardware switch deter-
mines which range is active.
P
partial linking: The linking of a file that will be linked again.
Q
quiet run: Suppresses the normal banner and the progress information.
R
RAM model: An autoinitialization model used by the linker when linking C
code. The linker uses this model when you invoke the linker with the -cr
option. The RAM model allows variables to be initialized at load time
instead of runtime.
relocation: A process in which the linker adjusts all the references to a sym-
bol when the symbol’s address changes.
F-6
ROM width: The width (in bits) of each output file, or, more specifically, the
width of a single data value in the file. The ROM width determines how
the utility partitions the data into output files. After the target words are
mapped to memory words, the memory words are broken into one or
more output files. The number of output files is determined by the ROM
width.
run address: The address where a section runs.
S
section: A relocatable block of code or data that will ultimately occupy con-
tiguous space in the TMS320C54x memory map.
section header: A portion of a COFF object file that contains information
about a section in the file. Each section has its own header; the header
points to the section’s starting address, contains the section’s size, etc.
section program counter: See SPC.
sign extend: To fill the unused MSBs of a value with the value’s sign bit.
simulator: A software development system that simulates TMS320C54x
operation.
source file: A file that contains C code or assembly language code that will
be compiled or assembled to form an object file.
SPC (Section Program counter): An element of the assembler that keeps
track of the current location within a section; each section has its own
SPC.
static: A kind of variable whose scope is confined to a function or a program.
The values of static variables are not discarded when the function or pro-
gram is exited; their previous value is resumed when the function or pro-
gram is re-entered.
storage class: Any entry in the symbol table that indicates how to access
a symbol.
string table: A table that stores symbol names that are longer than 8 charac-
ters (symbol names of 8 characters or longer cannot be stored in the
symbol table; instead, they are stored in the string table). The name por-
tion of the symbol’s entry points to the location of the string in the string
table.
structure: A collection of one or more variables grouped together under a
single name.
Glossary F-7
subsection: A smaller section within a section offering tighter control of the
memory map. See also section.
symbol: A string of alphanumeric characters that represents an address or
a value.
symbolic debugging: The ability of a software tool to retain symbolic infor-
mation so that it can be used by a debugging tool such as a simulator or
an emulator.
symbol table: A portion of a COFF object file that contains information
about the symbols that are defined and used by the file.
T
tag: An optional type name that can be assigned to a structure, union, or
enumeration.
target memory: Physical memory in a TMS320C54x system into which exe-
cutable object code is loaded.
.text: One of the default COFF sections. The .text section is an initialized
section that contains executable code. You can use the .text directive to
assemble code into the .text section.
U
unconfigured memory: Memory that is not defined as part of the memory
map and cannot be loaded with code or data.
uninitialized section: A COFF section that reserves space in the memory
map but that has no actual contents. These sections are built up with the
.bss and .usect directives.
UNION: An option of the SECTIONS directive that causes the linker to allo-
cate the same address to multiple sections.
union: A variable that may hold objects of different types and sizes.
unsigned: A kind of value that is treated as a positive number, regardless
of its actual sign.
W
well-defined expression: An expression that contains only symbols or
assembly-time constants that have been defined before they appear in
the expression.
word: A 16-bit addressable location in target memory.
F-8
TOKEN REFERENCE SEE (ALSO) . . .
abs500 command absolute lister, invoking
boot loader on-chip boot loader
boot table on-chip boot loader, boot table
COFF, conversion to hexadecimal format hex conversion utility
common object file format COFF
default, section COFF, sections
directives assembler directives
fill value holes
mnemonic-to-algebraic translator utility translator
path alternate directories
path environment variables
program counters SPC
section program counters SPC
widths memory widths
F-1
Index
Index
allocation 4-37
alignment 4-34, 6-41
binding 6-39 to 6-87
A blocking 6-41
default algorithm 6-66 to 6-68
-a defined F-1
archiver command 7-4 described 2-3
assembler option 3-5, 3-9 GROUP 6-58
hex conversion utility option 10-40 memory default 2-14, 6-40
linker option 6-8 sections 6-38 to 6-47
A_DIR environment variable 3-22, 6-13, 6-16 UNION 6-56
abs500 command. See absolute lister, invoking alternate directories
linker 6-14
absolute address, defined F-1
naming with -i option 3-21
absolute lister naming with A_DIR 3-22
creating the absolute listing file 3-4, 3-9, 8-2 naming with directives 3-21 to 3-23
defined F-1
-ar linker option 6-9
described 1-4
ar500 command 7-4
development flow 8-2
example 8-5 to 8-9 archive library
invoking 8-3 allocating individual members 6-43
options 8-3 alternate directory 6-13
back referencing 6-21
absolute listing
defined F-1
-a assembler option 3-5, 3-9
exhaustively reading 6-21
producing 8-2
macros 4-79
absolute output module object 6-28 to 6-29
producing 6-8 types of files 7-2
relocatable 6-9
archiver 1-3
addressing, byte vs. word 3-13, 6-23 commands 7-4
algebraic defined F-1
defined F-1 examples 7-6
source file 3-6 in the development flow 7-3
translation from mnemonic 11-1 to 11-10 invoking 7-4
.algebraic directive 4-27, 4-33 options 7-5
.align directive 4-19, 4-34 overview 7-2
compatibility with C1x/C2x/C2xx/C5x 4-10 arithmetic operators 3-40
alignment 4-19 to 4-20, 4-34 ARMS mode 3-19
defined F-1 .arms_off directive 3-19, 4-28
linker 6-41 .arms_on directive 3-19, 4-28
Index-1
Index
Index-2
Index
Index-3
Index
boot table. See on-chip boot loader, boot table C_DIR environment variable 6-13 to 6-16
boot.obj 6-80, 6-84 _c_int00 6-11, 6-84
-bootorg hex conversion utility option 10-29, 10-32 .c_mode directive 4-27, 4-42
-bootpage hex conversion utility option 10-29 .c54cm_off directive 3-17, 4-29
.break directive 4-24, 4-77 .c54cm_on directive 3-17, 4-29
listing control 4-21, 4-50 C54x compatibility mode 3-17
use in macros 5-15 C54X_A_DIR environment variable 3-22, 6-13
-bscr hex conversion utility option 10-29 C54X_C_DIR environment variable 6-13 to 6-16
.bss directive 4-11, 4-37 C55X_A_DIR environment variable 6-13
compatibility with C1x/C2x/C2xx/C5x 4-10 C55X_C_DIR environment variable 6-13 to 6-16
in sections 2-5 .char directive 4-16, 4-40
linker definition 6-73 character
.bss section 4-11, 4-37, A-3 constant 3-29
defined F-2 string 3-31
holes 6-76 .cinit
initializing 6-76 section 6-81 to 6-83
built-in functions 3-44, 5-8 tables 6-81
-byte, hex conversion utility option 10-37 cinit symbol 6-81 to 6-83
cl500 command 3-4
byte addressing 3-13, 6-23
.clink directive 4-11, 4-41
.byte directive 4-16, 4-40
COFF
limiting listing with .option directive 4-21, 4-88
array limitation A-27
auxiliary entries A-24 to A-28
C conversion to hexadecimal format 10-1 to 10-45
See also hex conversion utility
C default allocation 6-66
memory pool 6-12, 6-81 defined F-2
system stack 6-18, 6-81 file structure A-2 to A-4
file types 2-2
-c
headers
assembler option 3-5, 3-9
file A-5
linker option 6-10, 6-73 optional A-6
C code, linking 6-80 to 6-84 section A-7 to A-10
C compiler in the development flow 6-3, 10-2
block definitions B-3 initialized sections 2-7
COFF technical details A-1 line number entries B-7
defined F-2 linker 6-1
enumeration definitions B-9 loading a program 2-21
file identification B-4 object file example A-3
function definitions B-5 relocation 2-16 to 2-19, A-11 to A-12
line-number entries B-7 runtime relocation 2-20
line-number information A-13 to A-14 sections
linking 6-10, 6-80 to 6-84 allocation 2-3
member definitions B-8 assembler 2-5 to 2-12
special symbols A-17 to A-18 described 2-3 to 2-4
storage classes A-20 linker 2-13 to 2-15
structure definitions B-9 named 2-8, 6-74
symbol table entries B-11 special types 6-69
union definitions B-9 uninitialized 2-5 to 2-6
Index-4
Index
Index-5
Index
Index-6
Index
extended addressing, loading values into 3-46 function definitions A-18, A-27, A-28, B-5
external symbols 2-22 functions, built-in 3-44, 5-9
defined F-3
relocatable 3-42
G
-g
F assembler option 3-5, 3-10
linker option 6-12
-f linker option 6-11
global
.far_mode directive 4-27, 4-54
defined F-3
.fclist directive 4-21, 4-55 symbols 6-12
listing control 4-21, 4-50
.global directive 4-23, 4-60
use in macros 5-22
identifying external symbols 2-22
.fcnolist directive 4-21, 4-55 GROUP
listing control 4-21, 4-50 defined F-3
use in macros 5-22 linker directive 6-58
field, defined F-3
.field directive 4-16, 4-56
compatibility with C1x/C2x/C2xx/C5x 4-10 H
file -h
copy 3-5, 3-10 assembler option 3-5, 3-10
identification B-4 linker option 6-12
include 3-6, 3-10 .half directive 4-17, 4-63
file header limiting listing with .option directive 4-21
defined F-3 -hc assembler option 3-5, 3-10
structure A-5 -heap linker option
.file symbolic debugging directive B-4 .sysmem section 6-81
filenames described 6-12
as character strings 3-31 -help
copy/include files 3-21 assembler option 3-5, 3-10
extensions, changing defaults 8-3 linker option 6-6
list file 3-4, 3-9 hex conversion utility
macros, in macro libraries 5-14 command file 10-7 to 10-8
object code 3-4, 3-8 controlling the ROM device address 10-35 to
files ROMS specification 10-18 10-38
fill data width 10-10
MEMORY specification 6-33 defined F-4
ROMS specification 10-17 described 1-3
value development flow 10-2
default 6-11 error messages 10-45
explicit initialization 6-77 examples
setting 6-11 avoiding holes with multiple sections C-8 to
-fill hex conversion utility option 10-27 C-9
building a hex command file for two 8-bit
fill value. See hole
EPROMS C-3 to C-7
.float directive 4-16, 4-59 generating a boot table C-10 to C-16, C-17
compatibility with C1x/C2x/C2xx/C5x 4-10 to C-23
floating-point constants 4-59 image mode 10-26 to 10-27
.func symbolic debugging directive B-5 invoking 10-3 to 10-6
Index-7
Index
Index-8
Index
Index-9
Index
Index-10
Index
-mt assembler option 3-7, 3-11 booting from the parallel port 10-34
-mv assembler option 3-7, 3-11, 3-16 booting from the serial port 10-33
-mw assembler option 3-7, 3-11, 4-111 controlling ROM device address 10-36 to 10-38
description 10-28, 10-33 to 10-35
options
N -e 10-32
summary 10-29
name MEMORY specification 6-32 setting the entry point 10-32
named sections 2-8 using the boot loader 10-33 to 10-35
COFF format A-3 operands
.csect directive 4-46 defined F-6
defined F-5 field 3-26 to 3-27
.sect directive 2-8, 4-92 immediate addressing 3-26
.usect directive 2-8, 4-107 label 3-32
nested macros 5-23 local label 3-36
.newblock directive 4-27, 4-86 prefixes 3-26
source statement format 3-26 to 3-27
.no_remark directive 4-27
operator precedence order 3-40
.nolist directive 4-21, 4-71
same effect with .option directive 4-21 .option directive 4-21, 4-88
NOLOAD section 6-69 optional header
defined F-6
.noremark directive 4-87
format A-6
options
O absolute lister 8-3
archiver 7-5
-o linker option 6-17 assembler 3-4, 3-9
object cross-reference lister 9-3
code source listing 3-48 defined F-6
formats hex conversion utility 10-4 to 10-6
address bits 10-39 linker 6-6 to 6-22
ASCII-Hex 10-40 translator 11-4
Intel 10-41 -order hex conversion utility option 10-15
Motorola-S 10-42 ordering memory words 10-14 to 10-15
output width 10-39 origin
Tektronix 10-44 MEMORY specification 6-32
TI-Tagged 10-43 ROMS specification 10-17
library
output
altering search algorithm 6-13
executable 6-8 to 6-9
defined F-6
hex conversion utility 10-24
described 6-28 to 6-29
linker 6-3, 6-17, 6-85
runtime support 6-80
module
using the archiver to build 7-2
defined F-6
object file, defined F-5 name 6-17
object format converter, defined F-5 section
octal integer constants 3-28 allocation 6-38 to 6-47
on-chip boot loader defined F-6
boot table 10-28 to 10-34 displaying a message 6-20
booting from device peripheral 10-32 rules 6-67
booting from EPROM 10-34 output listing 4-21 to 4-22
Index-11
Index
P R
-r
paddr SECTIONS specification 10-23 archiver command 7-4
page assembler option 3-7, 3-11
eject 4-90 linker option 6-9, 6-78 to 6-79
length 4-70 -r assembler option 4-87
title 4-103 R MEMORY attribute 6-32
width 4-70 RAM model
.page directive 4-22, 4-90 autoinitialization 6-81
PAGE option MEMORY directive 6-30 to 6-32, defined F-6
6-64 to 6-66, 6-68 raw data, defined F-6
PAGE ROMS specification 10-16 recursive macros 5-23
pages .ref directive 4-23, 4-60
overlay 6-61 to 6-65 identifying external symbols 2-22
PAGE syntax 6-64 to 6-66 register symbols 3-34
parallel instructions, rules 3-16 relational operators 3-41
parentheses in expressions 3-39 relocatable
partial linking output module 6-9
defined F-6 symbols 3-42
described 6-78 to 6-79 relocation
path. See alternate directories; environment vari- at runtime 2-20
ables capabilities 6-8 to 6-9
defined F-6
pipeline conflicts 3-7
sections 2-16 to 2-19
.port_for_size directive 4-29 structuring information A-11 to A-12
.port_for_speed directive 4-29 .remark directive 4-27, 4-87
precedence groups 3-39 remarks, suppressing 4-87
predefined names, -d assembler option 3-5, 3-9 reserved words, linker 6-26
prefixes for operands 3-26 resetting local labels 4-86
program counters. See SPC ROM
program memory 6-30 device address 10-35 to 10-38
.pstring directive 4-17, 4-97 model
autoinitialization 6-82
--purecirc assembler option 3-7, 3-11
defined F-6
-pw , assembler option 3-7 width
defined F-7
Q described 10-11 to 10-13
romname ROMS specification 10-16
-q ROMS hex conversion utility directive 10-16 to
absolute lister option 8-3 10-21
Index-12
Index
Index-13
Index
Index-14
Index
Index-15
Index
V X
-v -x
archiver option 7-5 archiver command 7-4
assembler option 3-8 assembler option 3-8, 3-12, 3-51
linker option 6-20 hex conversion utility option 10-44
.var directive 4-110, 5-13 linker option 6-21
listing control 4-21, 4-50 X MEMORY attribute 6-32
variable length instructions 3-16 .xfloat directive 4-16, 4-59
variables, local, substitution symbols used as 5-13 .xlong directive 4-17, 4-75
.vectors 6-37 xref500 command 9-3
Index-16