Analog Devices, Inc. reserves the right to change this product without
prior notice. Information furnished by Analog Devices is believed to be
accurate and reliable. However, no responsibility is assumed by Analog
Devices for its use; nor for any infringement of patents or other rights of
third parties which may result from its use. No license is granted by implication or otherwise under the patent rights of Analog Devices, Inc.
Trademark and Service Mark Notice
The Analog Devices logo, VisualDSP++, Blackfin, SHARC, and TigerSHARC are registered trademarks of Analog Devices, Inc.
All other brand and product names are trademarks or service marks of
their respective owners.
CONTENTS
PREFACE
Purpose ......................................................................................... xiii
Intended Audience ........................................................................ xiii
Manual Contents ........................................................................... xiv
What’s New in this Manual ............................................................ xiv
Technical or Customer Support ....................................................... xv
Supported Processors ...................................................................... xvi
Product Information ...................................................................... xvi
Analog Devices Web Site .......................................................... xvi
VisualDSP++ Online Documentation ...................................... xvii
Technical Library CD ............................................................. xviii
Notation Conventions .................................................................. xviii
xiiVisualDSP++ 5.0 Assembler and Preprocessor Manual
PREFACE
Thank you for purchasing Analog Devices, Inc. development software for
digital signal processing (DSP) applications.
Purpose
The VisualDSP++ 5.0 Assembler and Preprocessor Manual contains infor-
mation about the assembler and preprocessor utilities for the following
Analog Devices, Inc. processor families—Blackfin® (ADSP-BFxxx),
SHARC® (ADSP-21xxx), and TigerSHARC® (ADSP-TSxxx) processors.
The manual describes how to write assembly programs for these processors
and provides reference information about related development software.
It also provides information on new and legacy syntax for assembler and
preprocessor directives and comments, as well as command-line switches.
Intended Audience
The primary audience for this manual is a programmer who is familiar
with Analog Devices processors. This manual assumes that the audience
has a working knowledge of the appropriate processor architecture and
instruction set. Programmers who are unfamiliar with Analog Devices
processors can use this manual, but should supplement it with other texts
(such as the appropriate hardware reference and programming reference
manuals) that describe your target architecture.
VisualDSP++ 5.0 Assembler and Preprocessor Manualxiii
Manual Contents
Manual Contents
The manual consists of:
•Chapter 1, “Assembler”
Provides an overview of the process of writing and building
assembly programs. It also provides information about assembler
switches, expressions, keywords, and directives.
•Chapter 2, “Preprocessor”
Provides procedures for using preprocessor commands within
assembly source files as well as the preprocessor’s command-line
interface options and command sets.
What’s New in this Manual
This revision of the VisualDSP++ 5.0 Assembler and Preprocessor Manual
documents assembler and preprocessor functionality that is new to VisualDSP++® 5.0 and updates (up to update 6), including support for new
ADSP-2146x SHARC processors.
In addition, modifications and corrections based on errata reports against
the previous revision of the manual have been made.
xivVisualDSP++ 5.0 Assembler and Preprocessor Manual
Technical or Customer Support
You can reach Analog Devices, Inc. Customer Support in the following
ways:
•Visit the Embedded Processing and DSP products Web site at
•Contact your Analog Devices, Inc. local sales office or authorized
distributor
•Send questions by mail to:
Analog Devices, Inc.
One Technology Way
P.O. Box 9106
Norwood, MA 02062-9106
USA
VisualDSP++ 5.0 Assembler and Preprocessor Manualxv
Supported Processors
Supported Processors
The assembler and preprocessor of VisualDSP++ 5.0 supports the following Analog Devices, Inc. processors.
•Blackfin (ADSP-BFxxx)
•SHARC (ADSP-21xxx)
•TigerSHARC (ADSP-TSxxx)
The majority of the information in this manual applies to all processors.
For a complete list of processors supported by VisualDSP++ 5.0, refer to
the online Help.
Product Information
Product information can be obtained from the Analog Devices Web site,
VisualDSP++ online Help system, and a technical library CD.
Analog Devices Web Site
The Analog Devices Web site, www.analog.com, provides information
about a broad range of products—analog integrated circuits, amplifiers,
converters, and digital signal processors.
To access a complete technical library for each processor family, go to
http://www.analog.com/processors/technical_library. The manuals
selection opens a list of current manuals related to the product as well as a
link to the previous revisions of the manuals. When locating your manual
title, note a possible errata check mark next to the title that leads to the
current correction report against the manual.
xviVisualDSP++ 5.0 Assembler and Preprocessor Manual
Preface
Also note,
MyAnalog.com is a free feature of the Analog Devices Web site
that allows customization of a Web page to display only the latest information about products you are interested in. You can choose to receive
weekly e-mail notifications containing updates to the Web pages that meet
your interests, including documentation errata against all manuals. MyAn-
alog.com
provides access to books, application notes, data sheets, code
examples, and more.
Visit MyAnalog.com to sign up. If you are a registered user, just log on.
Your user name is your e-mail address.
VisualDSP++ Online Documentation
Online documentation comprises the VisualDSP++ Help system, software
tools manuals, hardware tools manuals, processor manuals, Dinkum
Abridged C++ library, and FLEXnet License Tools documentation. You
can search easily across the entire VisualDSP++ documentation set for any
topic of interest.
For easy printing, supplementary Portable Documentation Format (.pdf)
files for all manuals are provided on the VisualDSP++ installation CD.
Each documentation file type is described as follows.
File Description
.chmHelp system files and manuals in Microsoft help format
.htm or
.html
.pdfVisualDSP++ and processor manuals in PDF format. Viewing and printing the
Dinkum Abridged C++ library and FLEXnet license tools software
documentation. Viewing and printing the .html files requires a browser, such as
Internet Explorer 6.0 (or higher).
.pdf files requires a PDF reader, such as Adobe Acrobat Reader (4.0 or higher).
VisualDSP++ 5.0 Assembler and Preprocessor Manualxvii
Notation Conventions
Technical Library CD
The technical library CD contains seminar materials, product highlights,
a selection guide, and documentation files of processor manuals, VisualDSP++ software manuals, and hardware tools manuals for the following
processor families: Blackfin, SHARC, TigerSHARC, ADSP-218x, and
ADSP-219x.
To order the technical library CD, go to http://www.analog.com/proces-
sors/technical_library
processor, click the request CD check mark, and fill out the order form.
Data sheets, which can be downloaded from the Analog Devices Web site,
change rapidly, and therefore are not included on the technical library
CD. Technical manuals change periodically. Check the Web site for the
latest manual revisions and associated documentation errata.
, navigate to the manuals page for your
Notation Conventions
Text conventions used in this manual are identified and described as
follows.
L
ExampleDescription
Close command
(File menu)
{this | that}Alternative required items in syntax descriptions appear within curly
[this | that]Optional items in syntax descriptions appear within brackets and sepa-
xviiiVisualDSP++ 5.0 Assembler and Preprocessor Manual
Additional conventions, which apply only to specific chapters, may
appear throughout this document.
Titles in in bold style reference sections indicate the location of an item
within the VisualDSP++ environment’s menu system (for example, the
Close command appears on the File menu).
brackets and separated by vertical bars; read the example as
that. One or the other is required.
rated by vertical bars; read the example as an optional
this or
this or that.
Preface
L
a
[
ExampleDescription
[this,…]Optional item lists in syntax descriptions appear within brackets
delimited by commas and terminated with an ellipse; read the example
as an optional comma-separated list of
.SECTIONCommands, directives, keywords, and feature names are in text with
letter gothic font.
filenameNon-keyword placeholders appear in text with italic style format.
Note: For correct operation, ...
A Note provides supplementary information on a related topic. In the
online version of this book, the word Note appears instead of this
symbol.
Caution: Incorrect device operation may result if ...
Caution: Device damage may result if ...
A Caution identifies conditions or inappropriate usage of the product
that could lead to undesirable results or product damage. In the online
version of this book, the word Caution appears instead of this symbol.
Warn in g: Injury to device users may result if ...
A Warning identifies conditions or inappropriate usage of the product
that could lead to conditions that are potentially hazardous for devices
users. In the online version of this book, the word Wa rning appears
instead of this symbol.
this.
VisualDSP++ 5.0 Assembler and Preprocessor Manualxix
Notation Conventions
xxVisualDSP++ 5.0 Assembler and Preprocessor Manual
1ASSEMBLER
This chapter provides information on how to use the assembler to develop
and assemble programs for SHARC (ADSP-21xxx), TigerSHARC
(ADSP-TSxxx), and Blackfin (ADSP-BFxxx) processors.
The chapter contains the following sections:
•“Assembler Guide” on page 1-2
Describes how to develop new programs using the processor’s
assembly language
•“Assembler Syntax Reference” on page 1-37
Provides the assembler rules and conventions of syntax used to
define symbols (identifiers), expressions, and to describe different
numeric and comment formats
•“Assembler Command-Line Reference” on page 1-141
Provides reference information on the assembler’s switches and
conventions
L
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-1
The code examples in this manual have been compiled using
VisualDSP++ 5.0 The examples compiled with other versions of
VisualDSP++ may result in build errors or different output
although the highlighted algorithms stand and should continue to
stand in future releases of VisualDSP++.
Assembler Guide
Assembler Guide
In VisualDSP++ 5.0, you can run the assembler drivers for each processor
family from the VisualDSP++ integrated debugging and development
environment (IDDE) or from an operating system command line The
assembler processes assembly source, data, and header files to produce an
object file. Assembler operations depend on two types of controls:
assembler directives and assembler switches.
VisualDSP++ 5.0 supports the following assembler drivers.
•easm21k.exe (for SHARC processors)
•easmts.exe (for TigerSHARC processors)
•easmblkfn.exe (for Blackfin processors)
This section describes how to develop new programs in the Analog
Devices processor assembly language. It provides information on how to
assemble your programs from the operating system’s command line.
Software developers using the assembler should be familiar with these
topics:
•“Writing Assembly Programs” on page 1-4
•“Using Assembler Support for C Structs” on page 1-21
•“Preprocessing a Program” on page 1-24
•“Using Assembler Feature Macros” on page 1-25
•“Generating Make Dependencies” on page 1-33
•“Reading a Listing File” on page 1-34
1-2VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
•“Enabling Statistical Profiling for Assembly Functions” on
page 1-35
•“Specifying Assembler Options in VisualDSP++” on page 1-170
For information about a processor’s architecture, including the instruction
set used when writing assembly programs, refer to the Hardware Reference
and the Programming Reference for the appropriate processor.
Assembler Overview
The assembler processes data from assembly source (.asm), data (.dat),
and header (.h) files to generate object files in executable and linkable
format (ELF), an industry-standard format for binary object files. The
object file has a .doj extension.
In addition to the object file, the assembler can produce a listing file
(.lst) that shows the correspondence between the binary code and the
source.
Assembler switches are specified from the VisualDSP++ IDDE or from the
command line used to invoke the assembler. These switches allow you to
control the assembly process of source, data, and header files. Use these
switches to enable and configure assembly features, such as search paths,
output file names, and macro preprocessing. For more information, see
“Assembler Command-Line Reference” on page 1-141.
You can also set assembler options via the Assemble page of the Project Options dialog box in VisualDSP++. For more information, see “Specify-
ing Assembler Options in VisualDSP++” on page 1-170.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-3
Assembler Guide
Writing Assembly Programs
Assembler directives are coded in assembly source files. The directives
allow you to define variables, set up hardware features, and identify program sections for placement within processor memory. The assembler uses
directives for guidance as it translates a source program into object code.
Write assembly language programs using the VisualDSP++ editor or any
editor that produces text files. Do not use a word processor that embeds
special control codes in the text. Use an .asm extension to source file
names to identify them as assembly source files.
Figure 1-1 shows a graphical overview of the assembly process. The figure
shows the preprocessor processing the assembly source (.asm) and header
(.h) files.
Assemble your source files from the VisualDSP++ environment or using
any mechanism, such as a batch file or makefile, that supports invoking an
appropriate assembler driver with a specified command-line command.
By default, the assembler processes an intermediate file to produce a
binary object file (.doj) and an optional listing file (.lst).
Object files produced by the processor assembler may be used as input to
the linker and archiver. You can archive the output of an assembly process
into a library file (.dlb), which can then be linked with other objects into
an executable. Use the linker to combine separately assembled object files
and objects from library files to produce an executable file. For more
information about the linker and archiver, refer to the VisualDSP++ 5.0 Linker and Utilities Manual.
A binary object file (
.doj) and an optional listing (.lst) file are final
results of the successful assembly.
The assembler listing file is a text file read for information on the results
of the assembly process. The listing file also provides information about
the imported C data structures. The listing file tells which imports were
used within the program, followed by a more detailed section. (See the
1-4VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Assembler
Preprocessor
Intermediate
preprocessed
file (.IS)
Assembly source file
(.ASP)
Data initialization file
(.DAT)
Header file
(.H)
Listing file
(.LST)
Object file
(.OBJ)
Figure 1-1. Assembler Input and Output Files
.IMPORT directive on page 1-90.) The file shows the name, total size, and
layout with offset for the members. The information appears at the end of
the listing. You must specify the -l switch (on page 1-159) to produce a
listing file.
The assembly source file may contain preprocessor commands, such as
#include
source program. The preprocessor’s only output, an intermediate source
file (
preprocessor output is a temporary file that is deleted during the assembly
process.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-5
, that cause the preprocessor to include header files (.h) into the
.is), is the assembler’s primary input. In normal operation, the
Assembler Guide
Program Content
Assembly source file statements include assembly instructions, assembler
directives, and preprocessor commands.
Assembly Instructions
Instructions adhere to the processor’s instruction set syntax, which is
documented in the processor’s Programming Reference. Each instruction
line must be terminated by a semicolon (;). On TigerSHARC processors,
each instruction line (which can contain up to 4 instructions) is terminated by an additional semicolon (;;). Figure 1-2 on page 1-8 shows an
example assembly source file.
To mark the location of an instruction, place an address label at the beginning of an instruction line or on the preceding line. End the label with a
colon (:) before beginning the instruction. Your program can then refer to
this memory location using the label instead of an address. The assembler
places no restriction on the number of characters in a label.
Labels are case sensitive. The assembler treats “outer” and “Outer” as
unique labels. For example (in Blackfin processors),
Assembler directives begin with a period (.) and end with a semicolon (;).
The assembler does not differentiate between directives in lowercase or
uppercase.
L
1-6VisualDSP++ 5.0 Assembler and Preprocessor Manual
This manual prints directives in uppercase to distinguish them
from other assembly statements.
For a complete description of the assembler’s directive set, see “Assembler
Directives” on page 1-67.
Preprocessor Commands
Preprocessor commands begin with a pound sign (#) and end with a
carriage return. The pound sign must be the first non-white space
character on the line containing the command. If the command is longer
than one line, use a backslash (\) and a carriage return to continue the
command onto the next line.
Do not put any characters between the backslash and the carriage return.
Unlike assembler directives, preprocessor commands are case sensitive and
must be lowercase. For example,
#include "string.h"
#define MAXIMUM 100
For more information, see “Writing Preprocessor Commands” on
page 2-3. For a list of the preprocessor commands, see “Preprocessor
Command-Line Reference” on page 2-45.
Program Structure
An assembly source file defines code (instructions) and data. It also
organizes the instructions and data to allow the use of the linker description file (
.ldf) to describe how code and data are mapped into the
memory on your target processor. The way you structure your code and
data into memory should follow the memory architecture of the target
processor.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-7
Assembler Guide
Use the
.SECTION directive to organize the code and data in assembly
source files. The .SECTION directive defines a grouping of instructions and
data that occupies contiguous memory addresses in the processor. The
name given in a .SECTION directive corresponds to an input section name
in the linker description file.
Table 1-1, Table 1-2, and Table 1-3 show suggested input section names
for data and code that can be used in your assembly source for various
processors. Using these predefined names in your sources makes it easier
to take advantage of the default .ldf file included in your DSP system.
However, you may also define your own sections. For information on
.ldf files, refer to the VisualDSP++ 5.0 Linker and Utilities Manual.
Table 1-1. Suggested Input Section Names for a SHARC .ldf File
.SECTION NameDescription
seg_pmcoA section in program memory that holds code
seg_dmdaA section in data memory that holds data
seg_pmdaA section in program memory that holds data
seg_rthA section in program memory that holds system initialization code
and interrupt service routines
seg_swco A section in short word memory that holds instructions encoded for
execution from short word memory.
NOTE: Applies to the ADSP-2146x processors only.
Table 1-2. Suggested Input Section Names for a TigerSHARC .ldf File
.SECTION NameDescription
data1A section that holds data in memory block M1
data2A section that holds data in memory block M2 (specified with the
PM memory qualifier)
programA section that holds code
1-8VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Table 1-3. Suggested Input Section Names for a Blackfin .ldf File
.SECTION NameDescription
data1A section that holds data
programA section that holds code
constdataA section that holds global data (which is declared as constant) and
literal constants such as strings and array initializers
Use sections in a program to group elements to meet hardware constraints.
For example, the ADSP-BF535 processor has a separate program and data
memory in Level 1 memory only. Level 2 memory and external memory
are not separated into instruction and data memory.
To group the code that resides in off-chip memory, declare a section for
that code and place that section in the selected memory with the linker.
The example assembly program defines three sections. Each section begins
with a
.SECTION directive or end-of-file.
.SECTION directive and ends with the occurrence of the next
Table 1-4 lists the sections in the source program:
Table 1-4. Sections in Source Programs
SectionBlackfinSHARCTigerSHARC
Data Section
Variables and buffers are declared and can be
initialized
Program Section
Data, instructions, and possibly other types of
statements are in this section, including statements that are needed for conditional assembly
data1
constdata
seg_rth
program
seg_dmdadata1
data2
seg_pmcoprogram
Figure 1-2, Figure 1-3 on page 1-14, and Figure 1-4 on page 1-17
describe assembly code file structure for each processor family. They show
how a program divides into sections that match the memory segmentation
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-9
Assembler Guide
of a DSP system. Notice that an assembly source may contain preprocessor commands (such as
#ifdef
SECTIONS{} commands define the .SECTION placements in the system’s
(for conditional assembly), or #define (to define macros). The
#include to include other files in source code),
physical memory as defined by the linker’s MEMORY{} command. Assembler
directives, such as .VAR (or .BYTE for Blackfin processors), appear within
sections to declare and initialize variables.
Code File Structure for SHARC Processors
Figure 1-2 describes assembly code file structure for SHARC processors.
Looking at Figure 1-2, notice that the .PRECISION and .ROUND_ZERO
directives inform the assembler to store floating-point data with 40-bit
precision and to round a floating-point value to a closer-to-zero value if it
does not fit in the 40-bit format.
LDF for SHARC Processors
Listing 1-1 shows a sample user-defined .ldf file for SHARC processors.
Looking at the file’s SECTIONS{} command, notice that the INPUT_SECTION
commands map to the names of memory sections (such as program, data1,
data2, ctor, heaptab, and so on) used in the example assembly sample
Figure 1-3 describes assembly code file structure for TigerSHARC
processors. Looking at Figure 1-3, notice that an assembly source may
contain preprocessor commands, such as #include (to include other files
in source code), #ifdef (for conditional assembly), or #define (to define
macros).
Assembler directives, such as .VAR, appear within sections to declare and
initialize variables.
LDF for TigerSHARC Processors
Listing 1-2 shows a sample user-defined .ldf file for TigerSHARC
processors. Looking at the file’s SECTIONS{} command, notice that the
INPUT_SECTION commands map to the names of memory sections (such as
program, data1, data2, ctor, heaptab, and so on) used in the example
assembly sample program.
Listing 1-2. Example Linker Description File for TigerSHARC Processors
Figure 1-4 describes the Blackfin processor’s assembly code file structure
and shows how a program divides into sections that match the memory
segmentation of Blackfin processors.
Figure 1-4. Assembly Source File Structure for Blackfin Processors
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-17
Assembler Guide
You can use sections in a program to group elements to meet hardware
constraints. For example, the ADSP-BF535 processor has a separate program and data memory in Level 1 memory only. Level 2 memory and
external memory are not separated into instruction and data memory.
LDF for Blackfin Processors
Listing 1-3 on page 1-18 shows a sample user-defined linker description
file (.ldf). Looking at the file’s SECTIONS{} command, notice that the
INPUT_SECTION commands map to sections program, data1, and
constdata.
Listing 1-3. Example Linker Description File for Blackfin Processors
You can interface your assembly program with a C or C++ program.
The C/C++ compiler supports two methods for mixing C/C++ and
assembly language:
•Embedding assembly code in C or C++ programs
•Linking together C or C++ and assembly routines
To embed (inline) assembly code in your C or C++ program, use the
asm() construct. To link together programs that contain C/C++ and
assembly routines, use assembly interface macros. These macros facilitate
the assembly of mixed routines. For more information about these
methods, see the VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for the appropriate target processor.
1-20VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
When writing a C or C++ program that interfaces with assembly, observe
the same rules that the compiler follows as it produces code to run on the
processor. These rules for compiled code define the compiler’s run-time
environment. Complying with a run-time environment means following
rules for memory usage, register usage, and variable names.
The definition of the run-time environment for the C/C++ compiler is
provided in the VisualDSP++ 5.0 C/C++ Compiler and Library Manual for
the appropriate target processor, which also includes a series of examples
to demonstrate how to mix C/C++ and assembly code.
Using Assembler Support for C Structs
The assembler supports C typedef/struct declarations within assembly
source. These assembler data directives and built-ins provide high-level
programming features with C structs in the assembler.
Data Directives:
.IMPORT (see on page 1-90)
.EXTERN STRUCT(see on page 1-83)
.STRUCT(see on page 1-130)
C Struct in Assembly Built-Ins:
OFFSETOF(struct/typedef,field(see on page 1-63)
SIZEOF(struct/typedef)(see on page 1-63)
Struct References:
struct->field (support nests; see “Struct References” on page 1-64)
For more information on C struct support, refer to the “-flags-compiler”
command-line switch on page 1-154 and to “Reading a Listing File” on
page 1-34.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-21
Assembler Guide
C structs in assembly features accept the full set of legal C symbol names,
including those that are otherwise reserved in the appropriate assembler.
For example,
•In the SHARC assembler,
I1, I2, and I3 are reserved keywords,
but it is legal to reference them in the context of the C struct in
assembly features.
•In the TigerSHARC assembler, J1, J2, and J3 are reserved
keywords, but it is legal to reference them in the context of the C
struct in assembly features.
•In the Blackfin assembler, as an example, “X” and “Z” are reserved
keywords, but it is legal to reference them in the context of the C
struct in assembly features.
The examples below show how to access the parts of the struct defined in
the header file, but they are not complete programs on their own. Refer to
your DSP project files for complete code examples.
Blackfin Example:
.IMPORT "Coordinate.h";
/* typedef struct Coordinate {
intX;
intY;
intZ;
} Coordinate;*/
.SECTION data1;
.STRUCT Coordinate Coord1 = {
X = 1,
Y = 4,
Z = 7
};
1-22VisualDSP++ 5.0 Assembler and Preprocessor Manual
.SECTION program;
P0.l = Coord1->X;
P0.h = Coord1->X;
P1.l = Coord1->Y;
P1.h = Coord1->Y;
P2.l = Coord1->Z;
P2.h = Coord1->Z;
P3.l = Coord1+OFFSETOF(Coordinate,Z);
P3.h = Coord1+OFFSETOF(Coordinate,Z);
SHARC Example:
.IMPORT "Samples.h";
/*typedef struct Samples {
int I1;
int I2;
int I3;
} Samples; */
Assembler
.SECTION/DM seg_dmda;
.STRUCT Samples Sample1 ={
I1 = 0x1000,
I2 = 0x2000,
I3 = 0x3000
};
.SECTION/PM seg_pmco;
doubleMe:
/* The code may look confusing, but I2 can be used both
as a register and a struct member name */
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-23
that have the same spelling as assembler keywords. This may not
always be possible if your application needs to use an existing set of
C header files.
Preprocessing a Program
The assembler includes a preprocessor that allows the use of C-style
preprocessor commands in your assembly source files. The preprocessor
automatically runs before the assembler unless you use the assembler’s -sp
(skip preprocessor) switch. Table 2-5 on page 2-23 lists preprocessor
commands and provides a brief description of each command.
You can see the command line that the assembler uses to invoke the preprocessor by adding the -v switch (on page 1-167) to the assembler
command line or by selecting the Generate verbose output option on the
Assemble page of the Project Options dialog box. See “Specifying Assem-
bler Options in VisualDSP++” on page 1-170.
Use preprocessor commands to modify assembly code. For example,
you can use the #include command to fill memory, load configuration
registers, or set up processor parameters. You can use the #define command to define constants and aliases for frequently used instruction
sequences. The preprocessor replaces each occurrence of the macro
reference with the corresponding value or series of instructions.
For better code readability, avoid using .STRUCT member names
For example, the
with the number
MAXIMUM macro from #define MAXIMUM 100 is replaced
100 during preprocessing.
1-24VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
For more information on the preprocessor command set, see “Preproces-
sor Command Reference” on page 2-22. For more information on the
preprocessor usage, see “-flags-pp -opt1 [,-opt2...]” on page 1-156.
L
For example,
#define EXTERN ox123
.EXTERN Coordinate;/* EXTERN not affected by macro */
#define MY_REG P0
MY_REG.1 = 14;/* MY_REG.1 is not expanded; */
There is one important difference between the assembler preprocessor and compiler preprocessor. The assembler preprocessor
treats the “.” character as part of an identifier. Thus, .EXTERN is a
single identifier and will not match a preprocessor macro EXTERN.
This behavior can affect how macro expansion is done for some
instructions.
/* "." is part of token */
Using Assembler Feature Macros
The assembler includes the command to invoke preprocessor macros to
define the context, such as the source language, the architecture, and the
specific processor. These feature macros allow programmers to use prepro-
cessor conditional commands to configure the source for assembly based
on the context.
Table 1-5 lists the set of feature macros for Blackfin processors. Table 1-6
on page 1-28 lists the set of feature macros for SHARC processors.
Table 1-7 on page 1-30 lists the set of feature macros for TigerSHARC
processors.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-25
Assembler Guide
Table 1-5. Feature Macros for Blackfin Processors
-D_LANGUAGE_ASM=1Always present
-D__ADSPBLACKFIN__ =1 Always present
-D__ADSPLPBLACKFIN__ =1Always present for non-ADSP-BF535 processors
-D__ADSPBF512__=1Present when running easmblkfn -proc ADSP-BF512
with the ADSP-BF512 processor
-D__ADSPBF514__=1Present when running easmblkfn -proc ADSP-BF514
with the ADSP-BF514 processor
-D__ADSPBF516__=1Present when running easmblkfn -proc ADSP-BF516
with the ADSP-BF516 processor
-D__ADSPBF522__=1Present when running easmblkfn -proc ADSP-BF522
with the ADSP-BF522 processor
-D__ADSPBF523__=1Present when running easmblkfn -proc ADSP-BF523
with the ADSP-BF523 processor
-D__ADSPBF524__=1Present when running easmblkfn -proc ADSP-BF524
with the ADSP-BF524 processor
-D__ADSPBF525__=1Present when running easmblkfn -proc ADSP-BF525
with the ADSP-BF525 processor
1-26VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Table 1-5. Feature Macros for Blackfin Processors (Cont’d)
-D__ADSPBF526__=1Present when running easmblkfn -proc ADSP-BF526
with the ADSP-BF526 processor
-D__ADSPBF527__=1Present when running easmblkfn -proc ADSP-BF527
with the ADSP-BF527 processor
-D__ADSPBF531__=1
-D__ADSP21531__=1
-D__ADSPBF532__=1
-D__ADSP21532__=1
-D__ADSPBF533__=1
-D__ADSP21533__=1
-D__ADSPBF534__=1Present when running easmblkfn -proc ADSP-BF534
Present when running easmblkfn -proc ADSP-BF531
with the ADSP-BF531 processor
Present when running easmblkfn -proc ADSP-BF532
with the ADSP-BF532 processor
Present when running easmblkfn -proc ADSP-BF533
with the ADSP-BF533 processor
with the ADSP-BF534 processor
-D__ADSPBF535__=1
-D__ADSP21535__=1
-D__ADSPBF536__=1Present when running easmblkfn -proc ADSP-BF536
Present when running easmblkfn -proc ADSP-BF535
with the ADSP-BF535 processor
with the ADSP-BF536 processor
-D__ADSPBF537__=1Present when running easmblkfn -proc ADSP-BF537
with the ADSP-BF537 processor
-D__ADSPBF538__=1Present when running easmblkfn -proc ADSP-BF538
with the ADSP-BF538 processor
-D__ADSPBF539__=1Present when running easmblkfn -proc ADSP-BF539
with the ADSP-BF539 processor
-D__ADSPBF542__=1Present when running easmblkfn -proc ADSP-BF542
with the ADSP-BF542 processor
-D__ADSPBF544__=1Present when running easmblkfn -proc ADSP-BF544
with the ADSP-BF544 processor
-D__ADSPBF547__=1Present when running easmblkfn -proc ADSP-BF547
with the ADSP-BF547processor
-D__ADSPBF548__=1Present when running easmblkfn -proc ADSP-BF548
with the ADSP-BF548 processor
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-27
Assembler Guide
Table 1-5. Feature Macros for Blackfin Processors (Cont’d)
-D__ADSPBF549__=1Present when running easmblkfn -proc ADSP-BF549
with the ADSP-BF549 processor
-D__ADSPBF561__=1Present when running easmblkfn -proc ADSP-BF561
with the ADSP-BF561 processor
Table 1-6. Feature Macros for SHARC Processors
-D_LANGUAGE_ASM=1Always present
-D__ADSP21000__=1 Always present
-D__ADSP21020__=1
-D__2102x__=1
-D__ADSP21060__=1
-D__2106x__=1
-D__ADSP21061__=1
-D__2106x__=1
-D__ADSP21062__=1
-D__2106x__=1
-D__ADSP21065L__=1
-D__2106x__=1
-D__ADSP21160__=1
-D__2116x__=1
-D__ADSP21161__=1
-D__2116x__=1
-D__ADSP21261__=1
-D__2126x__=1
-D__ADSP21262__=1
-D__2126x__=1
-D__ADSP21266__=1
-D__2126x__=1
-D__ADSP21267__=1
-D__2126x__=1
Present when running easm21K -proc ADSP-21020
with the ADSP-21020 processors
Present when running easm21K -proc ADSP-21060
with the ADSP-21060 processors
Present when running easm21K -proc ADSP-21061
with the ADSP-21061 processors
Present when running easm21K -proc ADSP-21062
with the ADSP-21062 processors
Present when running easm21K -proc ADSP-21065L
with the ADSP-21065L processors
Present when running easm21K -proc ADSP-21160
with the ADSP-21160 processors
Present when running easm21K -proc ADSP-21161
with the ADSP-21161 processors
Present when running easm21K -proc ADSP-21261
with the ADSP-21261 processors
Present when running easm21K -proc ADSP-21262
with the ADSP-21262 processors
Present when running easm21K -proc ADSP-21266
with the ADSP-21266 processors
Present when running easm21K -proc ADSP-21267
with the ADSP-21267 processors
1-28VisualDSP++ 5.0 Assembler and Preprocessor Manual
Table 1-6. Feature Macros for SHARC Processors (Cont’d)
Assembler
-D__ADSP21362__=1
-D__2136x__=1
-D__ADSP21363__=1
-D__2136x__=1
-D__ADSP21364__=1
-D__2136x__=1
-D__ADSP21365__=1
-D__2136x__=1
-D__ADSP21366__=1
-D__2136x__=1
-D__ADSP21367__=1
-D__2136x__=1
-D__ADSP21368__=1
-D__2136x__=1
-D__ADSP21369__=1
-D__2136x__=1
-D__ADSP2137x__=1
-D__2137x__=1
-D__ADSP21371__=1
-D__2137x__=1
-D__ADSP21375__=1
-D__2137x__=1
Present when running easm21K -proc ADSP-21362
with the ADSP-21362 processors
Present when running easm21K -proc ADSP-21363
with the ADSP-21363 processors
Present when running easm21K -proc ADSP-21364
with the ADSP-21364 processors
Present when running easm21K -proc ADSP-21365
with the ADSP-21365 processors
Present when running easm21K -proc ADSP-21366
with the ADSP-21366 processors
Present when running easm21K -proc ADSP-21367
with the ADSP-21367 processors
Present when running easm21K -proc ADSP-21368
with the ADSP-21368 processors
Present when running easm21K -proc ADSP-21369
with the ADSP-21369 processors
Present when running easm21K -proc ADSP-2137x
with the ADSP-2137x processors
Present when running easm21K -proc ADSP-21371
with the ADSP-21371 processors
Present when running easm21K -proc ADSP-21375
with the ADSP-21375 processors
-D__ADSP21462__=1
-D__2146x__=1
-D__214xx__=1
-D__ADSP21465__=1
-D__2146x__=1
-D__214xx__=1
-D__ADSP21467__=1
-D__2146x__=1
-D__214xx__=1
Present when running easm21K -proc ADSP-21462
with the ADSP-21462 processors
Present when running easm21K -proc ADSP-21465
with the ADSP-21465 processors
Present when running easm21K -proc ADSP-21467
with the ADSP-21467 processors
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-29
Assembler Guide
Table 1-6. Feature Macros for SHARC Processors (Cont’d)
-D__ADSP21469__=1
-D__2146x__=1
-D__214xx__=1
-D__NORMAL_WORD_CODE__=1Present when running
Present when running easm21K -proc ADSP-21469
with the ADSP-21469 processors
easm21K -proc ADSP-21462
easm21K -proc ADSP-21465
easm21K -proc ADSP-21467
easm21K -proc ADSP-21469 and building in normal-word
mode
-D__SHORT_WORD_CODE__=1Present when running
easm21K -proc ADSP-21462
easm21K -proc ADSP-21465
easm21K -proc ADSP-21467
easm21K -proc ADSP-21469 and building in short-word
mode
Table 1-7. Feature Macros for TigerSHARC Processors
-D_LANGUAGE_ASM =1Always present
-D__ADSPTS__ =1 Always present
-D__ADSPTS101__ =1Present when running easmts -proc ADSP-TS101
with the ADSP-TS101 processor
-D__ADSPTS201__ =1Present when running easmts -proc ADSP-TS201
with the ADSP-TS201 processor
-D__ADSPTS202__ =1Present when running easmts -proc ADSP-TS202
with the ADSP-TS202 processor
-D__ADSPTS203__ =1Present when running easmts -proc ADSP-TS203
with the ADSP-TS203 processor
-D__ADSPTS20x__ =1Present when running
easmts -proc ADSP-TS201 with the ADSP-TS201 processor
easmts -proc ADSP-TS202 with the ADSP-TS202 processor
asmts -proc ADSP-TS203 with the ADSP-TS203 processor
1-30VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
For
.IMPORT headers, the assembler calls the compiler driver with the
appropriate processor option, and the compiler sets the machine constants
accordingly (and defines -D_LANGUAGE_C=1). This macro is present when
used for C compiler calls to specify headers. It replaces -D_LANGUAGE_ASM.
Use the -verbose switch to verify what macro is default-defined.
Refer to Chapter 1 in the VisualDSP++ 5.0 C/C++ Compiler and Library Manual of the appropriate target processor for more
information.
The macro applies to all Analog Devices processors.
assembly--> ccts -proc ADSP-TS101
L
The -D__VISUALDSPVERSION__ predefined macro provides product version
information to VisualDSP++. The macro allows a preprocessing check to
be placed within code and is used to differentiate between VisualDSP++
releases and updates.
Syntax:
-D__VISUALDSPVERSION__=0xMMmmUUxx
Table 1-8 explains the macro parameters.
The
0xMMmmUUxx information is obtained from the <install_path>\Sys-
tem\VisualDSP.ini
If an unexpected problem occurs while trying to locate VisualDSP.ini or
while extracting information from the
__VISUALDSPVERSION__ macro is not encoded to the VisualDSP++ product
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-31
file. Initially, xx is set to “00”.
VisualDSP.ini file, the
Assembler Guide
Table 1-8. -D__VISUALDSPVERSION__ Decoding of Hex Value
ParameterDescription
MMVersionMajor. The major release number; for example, 4 in release 4.5.
mmVersionMinor. The minor release number; for example, 5 in release 4.5.
UUVersionPatch. The number of the release update; for example, 6 in release 4.5,
update 6.
xxReserved for future use (always 00 initially)
version. In the Error Check example below, the
0xffffffff
string is displayed as part of an error message when the version
-D__VISUALDSPVERSION__
information is unable to be encoded.
Code Example (Legacy ):
#if !defined(__VISUALDSPVERSION__)
#warning Building with VisualDSP++ 4.5 Update 5 or prior. No
__VISUALDSPVERSION__ available.
#endif
Code Example (VisualDSP++ 4.5 Update 6 or Later):
#if __VISUALDSPVERSION__ >= 0x04050600
#warning Building with VisualDSP++ 4.5 Update 6 or later
#endif
#if __VISUALDSPVERSION__ == 0x05000000
/* Building with VisualDSP++ 5.0 */
.VAR VersionBuildString[] = ‘Building with VisualDSP++ 5.0’;
1-32VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
#elif __VISUALDSPVERSION__ == 0x04050600
/* Building with VisualDSP++ 4.5, Update 6 */
.VAR VersionBuildString[] = 'Building with VisualDSP++ 4.5 Update
6';
#else
/* Building with unknown VisualDSP++ version */
.VAR VersionBuildString[] = 'Building with unknown VisualDSP++
version?';
#endif
Generating Make Dependencies
The assembler can generate make dependencies for a file, allowing
VisualDSP++ and other makefile-based build environments to determine
when to rebuild an object file due to changes in the input files. The assembly source file and any files identified in the #include commands, .IMPORT
directives, or buffer initializations (in .VAR and .STRUCT directives) constitute the make dependencies for an object file.
When you request make dependencies for the assembly, the assembler
produces the dependencies from buffer initializations. The assembler also
invokes the preprocessor to determine the make dependency from
#include commands, and the compiler to determine the make
In this case, defBF533.h includes defBF532.h, which also includes
def_LPBlackfin.h.
Reading a Listing File
A listing file (.lst) is an optional output text file that lists the results of
the assembly process. Listing files provide the following information:
•Address – The first column contains the offset from the .SECTION’s
base address.
•Opcode – The second column contains the hexadecimal opcode
that the assembler generates for the line of assembly source.
•Line – The third column contains the line number in the assembly
source file.
•Assembly Source – The fourth column contains the assembly
source line from the file.
The assembler listing file provides information about the imported C data
structures. It tells which imports were used within the program, followed
by a more detailed section. It shows the name, total size, and layout with
offset for the members. The information appears at the end of the listing.
You must specify the -l filename option (as described on page 1-159)
to produce a listing file.
1-34VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Enabling Statistical Profiling for Assembly
Functions
Use the following steps to enable statistical profiling in assembler sources.
1. When using the VisualDSP++ IDDE, use the Assemble page of the
Project Options dialog box (Figure 1-6 on page 1-171) to select
and/or set assembler functional options.
2. Select the Generate debug information option.
3. Mark ending function boundaries with .end labels in the assembler
source. For example:
.SECTION program;
.GLOBAL funk1;
funk1:
...
RTS;
funk1.end:
.GLOBAL funk2;
funk2:
...
RTS;
funk2.end:
If you have global functions without ending labels, the assembler
provides warnings when debug information is generated.
.GLOBAL funk3;
funk3:
...
RTS;
[Warning ea1121] "test.asm":14 funk3: -g assembly with
global function without ending label. Use 'funk3.end' or
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-35
Assembler Guide
'funk3.END' to mark the ending boundary of the function for
debugging information for automated statistical profiling
of assembly functions.
4. Add ending labels or selectively disable the warning by adding the
-Wsuppress 1121 option to the Additional options field on the
Assembly page (refer to “WARNING ea1121: Missing End Labels”
on page 1-157 for more information).
5. Choose Statistical Profiling -> New Profile or Linear Profiling -> New Profile, as appropriate. Assembler functions automatically
appear in the profiling window along with C functions. Click on
the function name to bring up the source containing the function
definition.
1-36VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Assembler Syntax Reference
When developing a source program in assembly language, include
preprocessor commands and assembler directives to control the program’s
processing and assembly. You must follow the assembler rules and syntax
conventions to define symbols (identifiers) and expressions, and to use
different numeric and comment formats.
Software developers who write assembly programs should be familiar with:
•“Assembler Keywords and Symbols” on page 1-38
•“Assembler Expressions” on page 1-50
•“Assembler Operators” on page 1-51
•“Numeric Formats” on page 1-56
•“Comment Conventions” on page 1-60
•“Conditional Assembly Directives” on page 1-60
•“C Struct Support in Assembly Built-In Functions” on page 1-63
•“Struct References” on page 1-64
•“Assembler Directives” on page 1-67
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-37
Assembler Syntax Reference
Assembler Keywords and Symbols
The assembler supports predefined keywords that include register and
bitfield names, assembly instructions, and assembler directives.
The following tables list assembler keywords for supported processors.
Although the keywords appear in uppercase, the keywords are case
insensitive in the assembler’s syntax. For example, the assembler does not
differentiate between MAX and max.
Table 1-9 lists the assembler keywords for Blackfin processors.
Table 1-10 on page 1-41 lists the keywords for SHARC processors.
Table 1-11 on page 1-44 lists the keywords for TigerSHARC processors.
Table 1-9. Blackfin Processor Assembler Keywords
.ALIGN.ASCII.ASM_ASSERT.ASSERT.BSS
.BYTE.BYTE2.BYTE4.DATA.ELIF
.ELSE.ENDIF.ELSE.ENDIF.EXTERN
.FILE.FILE_ATTR.GLOBAL.GLOBL.IF
.INC/BINARY.INCBIN.IMPORT.LEFTMARGIN.LIST
.LIST_DATA.LIST_DATFILE .LIST_DEFTAB.LIST_LOCTAB
.LONG.NEWPAGE.NOLIST.NOLIST_DATA.NOLIST_DATFILE
.NOLIST_WRAPDATA.PAGELENGTH.PAGEWIDTH.PREVIOUS
.SECTION.SET SYMBOL.SYMBOL.SHORT.STRUCT
.TEXT.TYPE.VAR.WEAK
A0A1ABORT ABSAC
ALIGN8ALIGN16ALIGN24AMNOPAN
ANDASHIFTASLASRASSIGN
ASTATAV0AV1AZ
B B0B1B2 B3
.
LIST_WRAPDATA
1-38VisualDSP++ 5.0 Assembler and Preprocessor Manual
Conditions which may be prefixed with X, Y, XY, NX, NY, and XY
AEQ ALE ALT MEQMLE
MLTSEQSF1SF0SLT
Conditions which may be prefixed with J, K, NJ, and NK
EQ LE LT CBQCB1
Conditions which may be prefixed with N
ISF0 ISF1 LC0E LC1EBM
FLAG0_INFLAG1_INFLAG2_INFLAG3_IN
1-48VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Extend these sets of keywords with symbols that declare sections,
variables, constants, and address labels. When defining symbols in
assembly source code, follow these conventions:
•Define symbols that are unique within the file in which they are
declared.
If you use a symbol in more than one file, use the
.GLOBAL assembly
directive to export the symbol from the file in which it is defined.
Then use the .EXTERN assembly directive to import the symbol into
other files.
•Begin symbols with alphabetic characters.
Symbols can use alphabetic characters (A—Z and a—z), digits (0—9),
and the special characters “$” and “_” (dollar sign and underscore)
as well as “.” (dot).
Symbols are case sensitive; so input_addr and INPUT_ADDR define
unique variables.
The dot, point, or period “.” as the first character of a symbol
triggers special behavior in the VisualDSP++ environment.
A symbol with a “.” as the first character cannot have a digit as the
second character. Such symbols will not appear in the symbol table,
which is accessible in the debugger. A symbol name in which the
first two characters are dots will not appear even in the symbol
table of the object.
The compiler and run-time libraries prepend “
_” to avoid using
symbols in the user namespace that begin with an alphabetic
character.
•Do not use a reserved keyword to define a symbol.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-49
Assembler Syntax Reference
•Match source and LDF sections’ symbols.
Ensure that
.SECTION name symbols do not conflict with the
linker’s keywords in the .ldf file. The linker uses sections’ name
symbols to place code and data in the processor’s memory.
For details, see the VisualDSP++ 5.0 Linker and Utilities Manual.
Ensure that .SECTION name symbols do not begin with the “.”
(dot).
•Terminate the definition of address label symbols with a colon (:).
•The reserved word list for processors includes some keywords with
commonly used spellings; therefore, ensure correct syntax spelling.
Address label symbols may appear at the beginning of an instruction line
or stand-alone on the preceding line.
The following disassociated lines of code demonstrate symbol usage.
.BYTE2 xoperand;/* xoperand is a 16-bit variable */
.BYTE4 input_array[10];/* input_array is a 32-bit wide*/
/* data buffer with 10 elements*/
sub_routine_1:/* sub_routine_1 is a label*/
.SECTION kernel;/* kernel is a section name*/
Assembler Expressions
The assembler can evaluate simple expressions in source code. The
assembler supports two types of expressions: constant expressions and
symbolic expressions.
1-50VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Constant Expressions
A constant expression is acceptable where a numeric value is expected in
an assembly instruction or in a preprocessor command. Constant expressions contain an arithmetic or logical operation on two or more numeric
constants. For example,
2.9e-5 + 1.29
(128-48)/3
0x55&
0x0f7.6r – 0.8r
For information about fraction type support, refer to “Fractional Type
Support” on page 1-57.
Symbolic Expressions
Symbolic expressions contain symbols, whose values may not be known
until link-time. For example,
Symbols in this type of expression are data variables, data buffers, and
program labels. In the first three examples above, the symbol name represents the address of the symbol. The fourth example combines that
meaning of a symbol with a use of the length operator (see Table 1-13).
Assembler Operators
Table 1-12 lists the assembler’s numeric and bitwise operators used in
constant expressions and address expressions. These operators are listed in
group order from highest precedence to lowest precedence. Operators
with the highest precedence are evaluated first. When two operators have
the same precedence, the assembler evaluates the left-most operator first.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-51
Assembler Syntax Reference
Relational operators are supported only in relational expressions in
conditional assembly, as described in “Conditional Assembly Directives”
on page 1-60.
Table 1-12. Operator Precedence
OperatorUsage DescriptionDesignationProcessors
(expression)expression in parentheses
evaluates first
ParenthesesAll
~
-
*
/
%
+
-
<<
>>
&Bitwise AND All
|Bitwise inclusive ORAll
^Bitwise exclusive OR TigerSHARC and
&&Logical ANDTigerSHARC only
||Logical ORTigerSHARC only
Ones complement
Unary minus
Multiply
Divide
Modulus
Addition
Subtraction
Shift left
Shift right
Tilde
Minus
Asterisk
Slash
Percentage
Plus
Minus
All
All
All
All
SHARC
If right-shifting a negative value, ones are shifted in from the MSB,
L
which preserves the sign bit.
The assembler also supports special operators. Table 1-13 lists and
describes special operators used in constant and address expressions.
The ADDRESS and LENGTH operators can be used with external symbols—
apply them to symbols that are defined in other sections as
.GLOBAL
symbols.
1-52VisualDSP++ 5.0 Assembler and Preprocessor Manual
Table 1-13. Special Assembler Operators
OperatorUsage Description
ADDRESS(symbol)Address of symbol
Note: Used with SHARC and TigerSHARC assemblers only.
BITPOS(constant)Bit position (Blackfin processors only)
Assembler
HI(expression)
LO(expression)
LENGTH(symbol)Length of symbol in number of elements (in a buffer/array)
symbolAddress pointer to symbol
Extracts the most significant 16 bits of expression.
Extracts the least significant 16 bits of expression.
Note: Used with the Blackfin assembler only where
replaces the ADRRESS() operator. The expression in the HI and
LO operators can be either symbolic or constant.
HI/LO
Blackfin Processor Example:
The following example demonstrates how Blackfin assembler operators are
used to load the length and address information into registers.
#define n 20
...
.SECTION data1;/* data section */
.VAR real_data [n];/* n=number of input sampless */
.SECTION program;/* code section */
P0.L = real_data;
P0.H = real_data;
P1=LENGTH(real_data);/* buffer's length */
LOOP loop1 LC0=P1;
LOOP_BEGIN loop1;
R0=[P0++];/* get next sample */
...
LOOP_END loop1;
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-53
Assembler Syntax Reference
The code fragment above initializes
P0 and P1 to the base address and
length, respectively, of the real_data buffer. The loop is executed 20
times.
The BITPOS() operator takes a bit constant (with one bit set) and returns
the position of the bit. Therefore, BITPOS(0x10) would return 4 and
The following example demonstrates how assembler operators are used to
load the length and address information into registers (when setting up
circular buffers in TigerSHARC processors).
.SECTION data1;/* Data segment */
.VAR real_data[n];/* n = number of input samples */
...
.SECTION program;/* Code segment */
/* Load the base address of */
the circular buffer */
JB3 = real_data;;
/* Load the index */
J3=real_data;;
/* Load the circular buffer length */
JL3 = LENGTH(real_data);;
/* Set loop counter 0 with buffer length */
LC0 = JL3;;
start:
XR0 = CB [J3 += 1];;/* Read data from the circular buffer */
if NLC0E, jump start;;
1-54VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
The code fragment above initializes
JB3 and JL3 to the base address and
length, respectively, of the real_data circular buffer. The buffer length
value contained in JL3 determines when addressing wraps around the top
of the buffer. For further information on circular buffers, refer to the
Hardware Reference of the target processor.
SHARC Processor Example:
The following code example determines the base address and length of the
real_data circular buffer. The buffer’s length value (contained in L5)
determines when addressing wraps around to the top of the buffer (when
setting up circular buffers in SHARC processors). For further information
on circular buffers, refer to the Hardware Reference of the target processor.
.SECTION/DM seg_dmda;/* data segment */
.VAR real_data[n];/* n=number of input samples */
...
.SECTION/PM seg_pmco;/* code segment */
B5=real_data;/* buffer base address */
/* I5 loads automatically */
L5=length(real_data);/* buffer’s length */
M6=1;/* post-modify I5 by 1 */
LCNTR=length(real_data)
,DO loopend UNTIL LCE;
/* loop counter=buffer’s length */
F0=DM(I5,M6);/* get next sample */
...
loopend:
...
L
with the legacy @ operator, it is recommended to use LENGTH() in
place of
@.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-55
Although the SHARC assembler accepts the source code written
Assembler Syntax Reference
Numeric Formats
Depending on the processor architectures, the assemblers support binary,
decimal, hexadecimal, floating-point, and fractional numeric formats
(bases) within expressions and assembly instructions. Table 1-14 describes
the notation conventions used by the assembler to distinguish between
numeric formats.
Table 1-14. Numeric Formats
ConventionDescription
0xnumberThe “0x” prefix indicates a hexadecimal number
B#number
b#number
number.number[e {+/-} number]Entry for floating-point number
numberNo prefix and no decimal point indicates a decimal number
numberrThe “r” suffix indicates a fractional number
The “B#” or “b#” prefix indicates a binary number
Due to the support for b# and B# binary notation, the preprocessor
L
stringization functionality is turned off, by default, to avoid
possible undesired stringization.
For more information, refer to the processor’s # (Argument),
-stringize, and the assembler’s -flags-pp -opt1 [,-opt2...] com-
mand-line switches.
Representation of Constants in Blackfin
The Blackfin assembler keeps an internal 32-bit signed representation
of all constant values. Keep this in mind when working with immediate
values. The immediate value is used by the assembler to determine the
instruction length (16 or 32 bit). The assembler selects the smallest
opcode that can accommodate the immediate value.
1-56VisualDSP++ 5.0 Assembler and Preprocessor Manual
If there is no opcode that can accommodate the value, semantic error
ea5003 is reported.
Examples:
R0 = -64;/* 16-bit instruction: -64 fits into
7-bit immediate value */
R0 = 0xBF;/* 32-bit instruction: 191 fits into 16-bit
immediate value */
R0 = 0xFFBF;/* ERROR:65471 doesn’t fit into 7 or 16-bit
immediate values */
R0 = 0xFFFFFFBF; /* 32-bit instruction: -65 fits into 16 bit
immediate value */
R0 = 0x8000;/* ERROR:32768 doesn’t fit into 7 or 16-bit
immediate values */
Fractional Type Support
Assembler
Fractional (fract) constants are specially marked floating-point constants
to be represented in fixed-point format. A fract constant uses the floating-point representation with a trailing “r”, where r stands for fract.
The legal range is [–1…1). This means the values must be greater than or
equal to –1 and less than 1. Fracts are represented as signed values.
/* [Error …] Fract constant '1.5r' is out of range.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-57
Assembler Syntax Reference
Fract constants must be greater than or equal to -1
and less than 1. */
L
(in .BYTE4/R32 or .VAR/R32) to support 32-bit initialization for use
with 1.31 fracts.
In Blackfin processors, fract 1.15 is a default. Use a /R32 qualifier
1.31 Fracts
Fracts supported by Analog Devices processors use 1.31 format, which
means a sign bit and “31 bits of fraction”. This is –1 to +1–2**31.
For example, 1.31 maps the constant 0.5r to 2**31.
The conversion formula used by processors to convert from floating-point
format to fixed-point format uses a scale factor of 31.
For example,
.VAR/R32 myFract = 0.5r;
// Fract output for 0.5r is 0x4000 0000
// sign bit + 31 bits
//0100 0000 0000 0000 0000 0000 0000 0000
//40000000= 0x4000 0000 =
.5r
.VAR/R32 myFract = -1.0r;
// Fract output for -1.0r is 0x8000 0000
// sign bit + 31 bits
//1000 0000 0000 0000 0000 0000 0000 0000
//8000 0000= 0x8000
0000 = -1.0r
.VAR/R32 myFract = -1.72471041E-03r;
// Fract output for -1.72471041E-03 is 0xFFC77C15
// sign bit + 31 bits
//1111 1111 1100 0111 0111 1100 0001 0101
//FFC77C 15
1-58VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
1.0r Special Case
1.0r is out-of-the-range fract. Specify 0x7FFF FFFF for the closest
approximation of 1.0r within the 1.31 representation.
Fractional Arithmetic
The assembler provides support for arithmetic expressions using
operations on fractional constants, consistent with the support for other
numeric types in constant expressions, as described in “Assembler Expres-
sions” on page 1-50.
The internal (intermediate) representation for expression evaluation is a
double floating-point value. Fract range checking is deferred until the
expression is evaluated. For example,
The assembler does not support arithmetic between fracts and integers.
For example,
.SECTION data1;
.VAR myFract = 1 - 0.5r;
[Error ea1998] "fract.asm":2 User Error: Illegal
mixing of types in expression.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-59
Assembler Syntax Reference
Comment Conventions
The assemblers support C and C++ style formats for inserting comments
in assembly sources. The assemblers do not support nested comments.
Table 1-15 lists and describes assembler comment conventions.
Table 1-15. Comment Conventions
ConventionDescription
/* comment */ A “/* */” string encloses a multiple-line comment
// commentA pair of slashes “//” begin a single-line comment
Conditional Assembly Directives
Conditional assembly directives are used for evaluation of assembly-time
constants using relational expressions. The expressions may include
relational and logical operations. In addition to integer arithmetic, the
operands may be the C structs in the SIZEOF() and OFFSETOF() assembly
built-in functions that return integers.
The conditional assembly directives include:
•.IF constant-relational-expression;
•.ELIFconstant-relational-expression;
•.ELSE;
•.ENDIF;
Conditional assembly blocks begin with an .IF directive and end with
.ENDIF directive. Table 1-16 shows examples of conditional directives.
an
Optionally, any number of
.ELIF and .ELSE directive pairs may appear
within a pair of .IF and .ENDIF directives. The conditional directives are
each terminated with a semi-colon “
;”, just like all existing assembler
1-60VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Table 1-16. Relational Operators for Conditional Assembly
OperatorPurposeConditional Directive Examples
!Not.IF !0;
>Greater than.IF ( SIZEOF(myStruct) > 16 );
>=Greater than or equal to.IF ( SIZEOF(myStruct) >= 16 );
<Less than.IF ( SIZEOF(myStruct) < 16 );
<=Less than or equal to.IF ( SIZEOF(myStruct) <= 16 );
directives. Conditional directives do not have to appear alone on a line.
These directives are in addition to the C-style
#endif preprocessing directives.
#if, #elif, #else, and
The .IF, .ELSE, .ELIF, and .ENDIF directives (in any case) are
L
reserved keywords.
The .IF conditional assembly directive must be used to query about C
structs in assembly using the
SIZEOF() and/or OFFSETOF() built-in
functions. These built-ins are evaluated at assembly time, so they cannot
appear in expressions in
#if preprocessor directives.
In addition, the SIZEOF() and OFFSETOF() built-in functions (see “C
Struct Support in Assembly Built-In Functions” on page 1-63) can be
used in relational expressions. Different code sequences can be included
based on the result of the expression.
For example,
SIZEOF(struct/typedef/C_base_type) is permitted.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-61
Assembler Syntax Reference
The assembler supports nested conditional directives. The outer
conditional result propagates to the inner condition, just as it does in C
preprocessing.
Assembler directives are distinct from preprocessor directives, as follows:
•The
# directives are evaluated during preprocessing by the
preprocessor. Therefore, preprocessor #if directives cannot use
assembler built-ins (see “C Struct Support in Assembly Built-In
Functions” on page 1-63).
•The conditional assembly directives are processed by the assembler
in a later pass. Therefore, you are able to write a relational or
logical expression whose value depends on the value of a #define.
For example,
.IF tryit == 2;
<some code>
.ELIF tryit >= 3;
<some more code>
.ELSE;
<some more code>
.ENDIF;
If you have “#define tryit 2”, the code <some code> is assembled,
and
<some more code> is not assembled.
•There are no parallel assembler directives for C-style directives
#define, #include, #ifdef, #if defined(name), #ifndef, and so
on.
1-62VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
C Struct Support in Assembly Built-In Functions
The assemblers support built-in functions that enable you to pass information obtained from the imported C struct layouts. The assemblers
currently support two built-in functions: OFFSETOF() and SIZEOF().
OFFSETOF Built-In Function
The OFFSETOF() built-in function is used to calculate the offset of a
specified member from the beginning of its parent data structure.
OFFSETOF(struct/typedef,memberName);
where:
struct/typedef – a struct VAR or a typedef can be supplied as the first
argument
memberName – a member name within the struct or typedef (second
argument)
L
SIZEOF Built-In Function
The
with an imported C struct or data member. It provides functionality
similar to its C counterpart.
SIZEOF(struct/typedef/C_base_type);
where:
The
A symbolic reference is a name followed by none or several qualifiers
to members.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-63
For SHARC and TigerSHARC processors, OFFSETOF() units are in
words. For Blackfin processors, OFFSETOF() units are in bytes.
SIZEOF() built-in function returns the amount of storage associated
SIZEOF() function takes a symbolic reference as its single argument.
Assembler Syntax Reference
The
SIZEOF() function gives the amount of storage associated with:
•An aggregate type (structure)
•A C base type (int, char, and so on)
•A member of a structure (any type)
For example (Blackfin processor code):
.IMPORT "Celebrity.h";
.EXTERN STRUCT Celebrity StNick;
L3 = SIZEOF(Celebrity);// typedef
L3 = SIZEOF(StNick);// struct var of typedef
Celebrity
L3 = SIZEOF(char);// C built-in type
L3 = SIZEOF(StNick->Town);// member of a struct var
L3 = SIZEOF(Celebrity->Town);// member of a struct typedef
L
priate for its processor. For SHARC and TigerSHARC processors,
units are in words. For Blackfin processors, units are in bytes.
When applied to a structure type or variable, SIZEOF() returns the actual
size, which may include padding bytes inserted for alignment. When
applied to a statically dimensioned array, SIZEOF() returns the size of the
entire array.
Struct References
A reference to a struct VAR provides an absolute address. For a fully
qualified reference to a member, the address is offset to the correct location within the struct. The assembler syntax for struct references is “->”.
The SIZEOF() built-in function returns the size in the units appro-
The following example references the address of
myStruct.
1-64VisualDSP++ 5.0 Assembler and Preprocessor Manual
Member5 located within
Assembler
myStruct->Member5
If the struct layout changes, there is no need to change the reference.
The assembler recalculates the offset when the source is reassembled with
the updated header.
Nested struct references are supported. For example,
myStruct->nestedRef->AnotherMember
L
are always referenced with “->” (not “.”) because “.” is a legal
character in identifiers in assembly and is not available as a struct
reference.
References within nested structures are permitted. A nested struct
definition can be provided in a single reference in assembly code, and a
nested struct via a pointer type requires more than one instruction.
Use the OFFSETOF() built-in function to avoid hard-coded offsets that may
become invalid if the struct layout changes in the future.
Following are two nested struct examples for .IMPORT "CHeaderFile.h".
Example 1:
Nested Reference Within the Struct Definition with
Appropriate C Declarations
C Code
struct Location {
char Town[16];
char State[16];
};
Unlike struct members in C, struct members in the assembler
struct myStructTag {
int field1;
struct Location NestedOne;
};
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-65
1-66VisualDSP++ 5.0 Assembler and Preprocessor Manual
Assembler
Assembler Directives
Directives in an assembly source file control the assembly process. Unlike
assembly instructions, directives do not produce opcodes during assembly.
Use the following general syntax for assembler directives
.directive [/qualifiers | arguments];
Each assembler directive starts with a period (
.) and ends with a
semicolon (;). Some directives take qualifiers and arguments. A directive’s
qualifier immediately follows the directive and is separated by a slash (/);
arguments follow qualifiers. Assembler directives can be uppercase or
lowercase; uppercase distinguishes directives from other symbols in your
source code.
Table 1-17 lists all currently supported assembler directives. A description
of each directive appears in the following sections. These directives were
added for GNU compatibility.
Table 1-17. Assembler Directive Summary
DirectiveDescription
.ALIGN
(on page 1-72)
.ALIGN_CODE
(on page 1-74)
.ASCII
(on page 1-76)
.BSSEquivalent to .SECTION/zero_init bsz;
Specifies an alignment requirement for data or code
Specifies an alignment requirement for code.
NOTE: TigerSHARC processors only.
Defines the number of significant bits in a floating-point value.
NOTE: SHARC processors only.
Reverts to a previously described
.SECTION
Allows prioritized symbol mapping in the linker
Provides better information in an X-REF file.
Refer to “.REFERENCE, Provide Better Info in an X-REF
File” on page 1-118 for more information.
NOTE: Blackfin processors only.
.RETAIN_NAME
Stops the linker from eliminating a symbol
(on page 1-118)
.ROUND_NEAREST
(on page 1-119)
.ROUND_MINUS
(on page 1-119)
Specifies the Round-to-Nearest mode.
NOTE: SHARC processors only.
Specifies the Round-to-Negative Infinity mode.
NOTE: SHARC processors only.
1-70VisualDSP++ 5.0 Assembler and Preprocessor Manual
Table 1-17. Assembler Directive Summary (Cont’d)
DirectiveDescription
Assembler
.ROUND_PLUS
(on page 1-119)
.ROUND_ZERO
(on page 1-119)
.SECTION
Specifies the Round-to-Positive Infinity mode.
NOTE: SHARC processors only.
Specifies the Round-to-Zero mode.
NOTE: SHARC processors only.
Marks the beginning of a section
(on page 1-122)
.SEGMENT
(on page 1-128)
.SEPARATE_MEM_SEGMENTS
(on page 1-128)
Legacy directive. Replaced with the .SECTION directive.
NOTE: SHARC processors only.
Specifies that two buffers should be placed into different
memory segments by the linker.
NOTE: TigerSHARC processors only.
.SET
Sets symbolic aliases
(on page 1-129)
.SHORT
(on page 1-129)
.STRUCT
(on page 1-130)
.TEXTEquivalent to .SECTION program;
Supports two-byte data initializer lists for GNU compatibility.
NOTE: Blackfin processors only.
Defines and initializes data objects based on C typedefs from
.IMPORT C header files
Refer to “.SECTION, Declare a Memory Section” on
page 1-122.
NOTE: Blackfin processors only.
.TYPE
Changes the default data type of a symbol; used by C compiler
(on page 1-134)
.VAR
Defines and initializes 32-bit data objects
(on page 1-135)
.WEAK
Creates a weak definition or reference
(on page 1-140)
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-71
Assembler Syntax Reference
.ALIGN, Specify an Address Alignment
The
.ALIGN directive forces the address alignment of an instruction or data
item. The assembler sets the alignment of the section to match the largest
alignment requirement specified in the section and inserts padding at each
alignment location to ensure that the following item has the proper offset
from the start of the section to maintain the requested alignment. The
linker honors the alignment specified by the assembler when placing the
section in memory, thus guaranteeing the integrity of the alignment of
each element aligned with a .ALIGN directive.
You also can use the INPUT_SECTION_ALIGN(#number) LDF command (in
the .ldf file) to force all the following input sections to the specified
alignment. Refer to the VisualDSP++ 5.0 Linker and Utilities Manual for
more information on section alignment.
Syntax:
.ALIGN expression;
where
expression – evaluates to an integer. It specifies an alignment require-
ment; its value must be a power of 2. When aligning a data item or
instruction, the assembler adjusts the address of the current location
counter to the next address that can be divided by the value of
expression, with no remainder. The expression set to 0 or 1 signifies no
address alignment requirement.
The linker stops allocating padding for symbols aligned by 16 or more.
L
1-72VisualDSP++ 5.0 Assembler and Preprocessor Manual
In the absence of the .ALIGN directive, the default address
alignment is 1.
Assembler
Example:
In the following example, the assembler sets the alignment of the section
to 4 to match the value specified in the second alignment directive. This
satisfies the first alignment directive as well, since any item alignment on
an address multiple of 4 is also aligned on a multiple of 2. If the target is a
byte-addressed processor, such as Blackfin, there is no padding inserted
between “single” and “samples” since
.VAR creates a four-byte word of
storage. If the target is a processor on which the .VAR directive reserves a
one-address unit, such as SHARC, three words of padding follow “single”
in the section produced by the assembler.
...
.ALIGN 1;/* no alignment requirement */
...
.SECTION data1;
.ALIGN 2;
.VAR single;/* aligns the data item on the word boundary,
at the location with the address value that can
be evenly divided by 2 */
.ALIGN 4;
.VAR samples1[100]="data1.dat";
/* aligns the first data item on the double-word
boundary, at the location with the address value
that can be evenly divided by 4; advances other
data items consecutively */
L
as .VAR.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-73
The Blackfin assembler accepts .BYTE, .BYTE2, and .BYTE4 as well
Assembler Syntax Reference
.ALIGN_CODE, Specify an Address Alignment
L
Used with TigerSHARC processors only.
The .ALIGN_CODE directive forces the address alignment of an instruction
within the .SECTION in which it is used. .ALIGN_CODE is similar to the
.ALIGN directive, but whereas .ALIGN causes the code to be padded with
0s, .ALIGN_CODE pads with NOPs. The .ALIGN_CODE directive is used to
align instructions.
Refer to the VisualDSP++ 5.0 Linker and Utilities Manual for more information on section alignment.
Syntax:
.ALIGN_CODE expression;
where
expression – evaluates to an integer. It specifies an alignment require-
ment; its value must be a power of 2. In TigerSHARC processors, the
expression value is usually 4. When aligning a data item or instruction,
the assembler adjusts the address of the current location counter to the
next address that is divisible by the value of the expression. The expression set to 0 or 1 signifies no address alignment requirement.
L
Example:
.ALIGN_CODE 0;/* no alignment requirement */
...
.ALIGN_CODE 1;/* no alignment requirement */
...
.SECTION program;
.ALIGN_CODE 4;
1-74VisualDSP++ 5.0 Assembler and Preprocessor Manual
In the absence of the .ALIGN_CODE directive, the default address
alignment is 1.
JUMP LABEL;;
/* Jump instruction aligned to four word boundary.
If necessary, padding will be done with NOPs */
Assembler
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-75
Assembler Syntax Reference
.ASCII
L
Used with Blackfin processors only.
The .ASCII directive initializes a data location with one or more characters from a double-quoted ASCII string. This is equivalent to the .BYTE
directive. Note that the syntax differs from the .BYTE directive as follows:
•There is no “=” sign
•The string is enclosed in double-quotes, not single quotes
Syntax:
.ASCII “string” ;
Example:
.SECTION data1;
ASCII_String:
.TYPE ASCII_String,STT_OBJECT;
.ASCII "ABCD";
.ASCII_String.end:
Byte_String:
.TYPE Byte_String,STT_OBJECT;
.Byte = ‘ABCD’;
.Byte_String.end:
1-76VisualDSP++ 5.0 Assembler and Preprocessor Manual
.BYTE, Declare a Byte Data Variable or Buffer
Assembler
L
Used with Blackfin processors only.
The .BYTE, .BYTE2, and .BYTE4 directives declare and optionally initialize
one-, two-, and four-byte data objects, respectively. Note that the .BYTE4
directive performs the same function as the .VAR directive.
Syntax:
When declaring and/or initializing memory variables or buffer elements,
use one of these forms:
varName – user-defined symbols that name variables
bufferName – user-defined symbols that name buffers
= initExpression,varName2 =initExpression2,…
] = "fileName";
fileName – indicates that the elements of a buffer get their initial values
from the fileName data file. The <fileName> parameter can consist of the
actual name and path specification for the data file. If the initialization file
is in current directory of your operating system, only the
be given inside double quote (
" ") characters. Note that when reading in a
fileName need
data file, the assembler reads in whitespace-separated lists of decimal digits
or hex strings.
VisualDSP++ 5.0 Assembler and Preprocessor Manual1-77
Assembler Syntax Reference
If the file name is not found in the current directory, the assembler looks
in the directories in the processor
include path. You may use the -I
switch (see on page 1-158) to add a directory to the processor include
path.
Initializing from files is useful for loading buffers with data, such as filter
coefficients or FFT phase rotation factors that are generated by other
programs. The assembler determines how the values are stored in memory
when it reads the data files.
Ellipsis (…) – represents a comma-delimited list of parameters.
initExpressions parameters – sets initial values for variables and buffer
elements
L
associated buffer in words. The number of initialization elements
defines length of an implicit-size buffer. The brackets [] that
enclose the optional [length] are required. For more information,
see the following .BYTE examples.
In addition, use a /R32 qualifier (.BYTE4/R32) to support 32-bit
initialization for use with 1.31 fracts (see on page 1-57).
The following lines of code demonstrate .BYTE directives:
When declaring or initializing variables with .BYTE, consider constraints
applied to the .VAR directive. The .VAR directive allocates and optionally
initializes 32-bit data objects. For information about the .VAR directive,
refer to information on page 1-135.
ASCII String Initialization Support
The assembler supports ASCII string initialization. This allows the full use
of the ASCII character set, including digits and special characters.
In Blackfin processors, ASCII initialization can be provided with .BYTE,
.BYTE2, or .VAR directives. The most likely use is the .BYTE directive where
char is represented by one byte versus a .VAR directive in which each
each
char needs four bytes. The characters are stored in the upper byte of
32-bit words. The LSBs are cleared.
String initialization takes one of the following forms: