ARM IAR Assembler Reference Guide
ARM IAR Assembler Reference Guide
Reference Guide
AARM-7
COPYRIGHT NOTICE
© Copyright 2006 IAR Systems. All rights reserved.
No part of this document may be reproduced without the prior written consent of IAR
Systems. The software described in this document is furnished under a license and
may only be used or copied in accordance with the terms of such a license.
DISCLAIMER
The information in this document is subject to change without notice and does not
represent a commitment on any part of IAR Systems. While the information contained
herein is assumed to be accurate, IAR Systems assumes no responsibility for any
errors or omissions.
In no event shall IAR Systems, its employees, its contractors, or the authors of this
document be liable for special, direct, indirect, or consequential damage, losses, costs,
charges, claims, demands, claim for lost profits, fees, or expenses of any nature or
kind.
TRADEMARKS
IAR Systems, From Idea to Target, IAR Embedded Workbench, visualSTATE, IAR
MakeApp and C-SPY are trademarks owned by IAR Systems AB.
ARM and Thumb are registered trademarks of Advanced RISC Machines Ltd.
Microsoft and Windows are registered trademarks of Microsoft Corporation.
All other product names are trademarks or registered trademarks of their respective
owners.
EDITION NOTICE
Seventh edition: June 2006
Part number: AARM-7
This guide applies to version 4.x of the ARM IAR Embedded Workbench® IDE.
AARM-7
Contents
Tables ..................................................................................................................................... vii
Preface .................................................................................................................................. ix
Who should read this guide ..........................................................................ix
How to use this guide ........................................................................................ix
What this guide contains ................................................................................ix
Other documentation ........................................................................................x
Document conventions .....................................................................................x
Introduction to the ARM IAR Assembler ................................... 1
Source format ..........................................................................................................1
Assembler expressions ......................................................................................2
TRUE and FALSE ...........................................................................................2
Using symbols in relocatable expressions ..................................................2
Symbols ..............................................................................................................3
Labels ..................................................................................................................3
Integer constants ...............................................................................................4
ASCII character constants ..............................................................................4
Floating-point constants .................................................................................5
Predefined symbols ..........................................................................................5
Register symbols ....................................................................................................7
Programming hints ..............................................................................................7
Accessing special function registers ............................................................8
Using C-style preprocessor directives .........................................................8
Output formats .......................................................................................................8
Assembler options .................................................................................................. 9
Setting assembler options ...............................................................................9
Extended command line file ..........................................................................9
Assembler environment variables ............................................................. 10
Summary of assembler options ............................................................... 11
iii
AARM-7
Descriptions of assembler options ......................................................... 12
Assembler operators ......................................................................................... 23
Precedence of operators ............................................................................... 23
Summary of assembler operators .......................................................... 23
Unary operators – 1 ...................................................................................... 23
Multiplicative arithmetic operators – 2 .................................................... 24
Additive arithmetic operators – 3 .............................................................. 24
Shift operators – 4 ......................................................................................... 24
AND operators – 5 ........................................................................................ 24
OR operators – 6 ........................................................................................... 24
Comparison operators – 7 ........................................................................... 25
Operator synonyms ....................................................................................... 25
Descriptions of operators ............................................................................. 26
Assembler directives .......................................................................................... 37
Summary of directives .................................................................................... 37
Syntax conventions ........................................................................................... 41
Labels and comments ................................................................................... 41
Parameters ...................................................................................................... 42
Module control directives ............................................................................. 42
Syntax .............................................................................................................. 42
Parameters ...................................................................................................... 42
Description ..................................................................................................... 43
Symbol control directives ............................................................................ 45
Syntax .............................................................................................................. 45
Parameters ...................................................................................................... 45
Description ..................................................................................................... 45
Examples ......................................................................................................... 46
Mode control directives ................................................................................. 47
Syntax .............................................................................................................. 47
Description ..................................................................................................... 47
Examples ......................................................................................................... 48
Segment control directives ......................................................................... 49
Syntax .............................................................................................................. 49
AARM-7
Contents
Parameters ...................................................................................................... 49
Description ..................................................................................................... 50
Examples ......................................................................................................... 52
Value assignment directives ....................................................................... 54
Syntax .............................................................................................................. 54
Parameters ...................................................................................................... 55
Description ..................................................................................................... 55
Examples ......................................................................................................... 56
Conditional assembly directives .............................................................. 58
Syntax .............................................................................................................. 58
Parameters ...................................................................................................... 59
Description ..................................................................................................... 59
Examples ......................................................................................................... 59
Macro processing directives ....................................................................... 60
Syntax .............................................................................................................. 60
Parameters ...................................................................................................... 60
Description ..................................................................................................... 61
Examples ......................................................................................................... 64
Listing control directives .............................................................................. 69
Syntax .............................................................................................................. 69
Parameters ...................................................................................................... 69
Description ..................................................................................................... 70
Examples ......................................................................................................... 71
C-style preprocessor directives ................................................................ 74
Syntax .............................................................................................................. 74
Parameters ...................................................................................................... 75
Description ..................................................................................................... 75
Examples ......................................................................................................... 77
Data definition or allocation directives .............................................. 78
Syntax .............................................................................................................. 78
Parameters ...................................................................................................... 79
Description ..................................................................................................... 79
Examples ......................................................................................................... 79
AARM-7
Assembler control directives ..................................................................... 80
Syntax .............................................................................................................. 81
Parameters ...................................................................................................... 81
Description ..................................................................................................... 81
Examples ......................................................................................................... 82
Call frame information directives .......................................................... 83
Syntax .............................................................................................................. 84
Parameters ...................................................................................................... 86
Descriptions .................................................................................................... 86
Simple rules .................................................................................................... 90
CFI expressions ............................................................................................. 92
Example ........................................................................................................... 94
Assembler pseudo-instructions ............................................................ 97
Summary .................................................................................................................. 97
Descriptions of pseudo-instructions ...................................................... 98
Assembler diagnostics .................................................................................... 109
Message format ................................................................................................. 109
Severity levels ..................................................................................................... 109
Assembly warning messages .................................................................... 109
Command line error messages ................................................................. 109
Assembly error messages .......................................................................... 109
Assembly fatal error messages ................................................................. 109
Assembler internal error messages .......................................................... 110
Migrating to the ARM IAR Assembler ........................................ 111
Introduction ......................................................................................................... 111
Thumb code labels ...................................................................................... 111
Alternative register names ....................................................................... 112
Alternative mnemonics ............................................................................... 113
Operator synonyms ........................................................................................ 114
Warning messages .......................................................................................... 115
Index .................................................................................................................................... 117
AARM-7
Tables
1: Typographic conventions used in this guide .......................................................... x
2: Integer constant formats ......................................................................................... 4
3: ASCII character constant formats .......................................................................... 4
4: Floating-point constants ......................................................................................... 5
5: Predefined symbols ................................................................................................ 5
6: Predefined register symbols ................................................................................... 7
7: Assembler error return codes ............................................................................... 10
8: Asssembler environment variables ...................................................................... 10
9: Assembler options summary ................................................................................ 11
10: Conditional list (-c) ............................................................................................ 12
11: Controlling case sensitivity in user symbols (-s) ............................................... 19
12: Disabling assembler warnings (-w) .................................................................... 20
13: Including cross-references in assembler list file (-x) ......................................... 21
14: Operator synonyms ............................................................................................ 25
15: Assembler directives summary .......................................................................... 37
16: Assembler directive parameters ......................................................................... 42
17: Module control directives .................................................................................. 42
18: Symbol control directives .................................................................................. 45
19: Mode control directives ..................................................................................... 47
20: Segment control directives ................................................................................. 49
21: Value assignment directives ............................................................................... 54
22: Conditional assembly directives ........................................................................ 58
23: Macro processing directives ............................................................................... 60
24: Listing control directives ................................................................................... 69
25: C-style preprocessor directives .......................................................................... 74
26: Data definition or allocation directives .............................................................. 78
27: Assembler control directives .............................................................................. 80
28: Call frame information directives ...................................................................... 83
29: Unary operators in CFI expressions ................................................................... 93
30: Binary operators in CFI expressions .................................................................. 93
31: Ternary operators in CFI expressions ................................................................ 94
vii
AARM-7
32: Code sample with backtrace rows and columns ................................................ 95
33: Pseudo-instructions ............................................................................................ 97
34: Alternative register names ............................................................................... 112
35: Alternative mnemonics .................................................................................... 113
36: Operator synonyms .......................................................................................... 114
AARM-7
Preface
Welcome to the ARM® IAR Assembler Reference Guide. The purpose of this
guide is to provide you with detailed reference information that can help you
to use the ARM IAR Assembler to best suit your application requirements.
ix
AARM-7
Other documentation
Other documentation
The complete set of IAR Systems development tools for the ARM cores is described
in a series of guides. For information about:
● Using the IAR Embedded Workbench® and the IAR C-SPY® debugger, refer to
the ARM® IAR Embedded Workbench® IDE User Guide
● Programming for the ARM IAR C/C++ Compiler, refer to the ARM® IAR C/C++
Compiler Reference Guide
● Using the IAR XLINK linker and the IAR XLIB librarian, refer to the IAR Linker
and Library Tools Reference Guide
● Using the IAR DLIB Library, refer to the online help system
● Porting application code and projects created with a previous ARM® IAR
Embedded Workbench IDE, refer to the ARM® IAR Embedded Workbench
Migration Guide.
Online versions of these guides are delivered on the installation media and available
from the Help menu in the IAR Embedded Workbench. Some of them are also
delivered as printed books.
Document conventions
This guide uses the following typographic conventions:
Style Used for
AARM-7
Preface
bold Names of menus, menu commands, buttons, and dialog boxes that
appear on the screen.
reference A cross-reference within or to another part of this guide.
… An ellipsis indicates that the previous item can be repeated an arbitrary
number of times.
Identifies instructions specific to the versions of the IAR Systems tools
for the IAR Embedded Workbench interface.
Identifies instructions specific to the command line versions of IAR
Systems development tools.
Table 1: Typographic conventions used in this guide (Continued)
xi
AARM-7
Document conventions
AARM-7
Introduction to the ARM
IAR Assembler
This chapter describes the source code format for the ARM IAR Assembler
and provides programming hints.
Refer to Advanced RISC Machines Ltd’s hardware documentation for syntax
descriptions of the instruction mnemonics.
Source format
The format of an assembler source line is as follows:
[label [:]] [operation] [operands] [; comment]
where the components are as follows:
label A label, which is assigned the value and type of the current
program location counter (PLC). The : (colon) is optional if the
label starts in the first column. When using inline assembler in a
C/C++ program, the colon is mandatory.
AARM-7
Assembler expressions
Assembler expressions
Expressions can consist of operands and operators. The assembler will accept a wide
range of expressions, including both arithmetic and logical operations. All operators
use 32-bit two’s complement integers, and range checking is only performed when a
value is used for generating code.
Expressions are evaluated from left to right, unless this order is overridden by the
priority of operators; see also Precedence of operators, page 23.
The following operands are valid in an expression:
● User-defined symbols and labels.
● Constants, excluding floating-point constants.
● The program location counter (PLC) symbol, . (period).
These are described in greater detail in the following sections.
The valid operators are described in the chapter Assembler operators, page 23.
For example, a program could define the segments DATASEG and CODESEG as
follows:
EXTERN third
RSEG DATASEG : DATA (2)
first: DATA
second: DC32 4
Then in the segment CODESEG the following instructions are legal:
RSEG CODESEG : CODE (2)
CODE32
; DATASEG must be linked in the range 0-255,
; otherwise the immediate values #first etc.
AARM-7
Introduction to the ARM IAR Assembler
SYMBOLS
User-defined symbols can be up to 255 characters long, and all characters are
significant.
Symbols must begin with a letter, a–z or A–Z, ? (question mark), or _ (underscore).
They can include the digits 0–9 and $ (dollar).
Symbols may contain any printable characters if they are quoted with ` (backquote).
For example:
`strange#label`
For built-in symbols like instructions, registers, operators, and directives, case is
insignificant. For user-defined symbols case is by default significant but can be turned
on and off using the Case sensitive user symbols (-s) assembler option. See page 19
for additional information.
LABELS
Symbols used for memory locations are referred to as labels.
AARM-7
Assembler expressions
INTEGER CONSTANTS
Since all IAR Systems assemblers use 32-bit two’s complement internal arithmetic,
integers have a (signed) range from -2147483648 to 2147483647.
Constants are written as a sequence of digits with an optional - (minus) sign in front
to indicate a negative number. Commas and decimal points are not permitted.
The following types of number representation are supported:
Integer type Example
Binary 1010b, b'1010'
Octal 1234q, q'1234'
Decimal 1234, -1, d'1234'
Hexadecimal 0FFFFh, 0xFFFF, h'FFFF'
Table 2: Integer constant formats
Note: Both the prefix and the suffix can be written with either uppercase or lowercase
letters.
AARM-7
Introduction to the ARM IAR Assembler
Format Value
\' '
\\ \
Table 3: ASCII character constant formats
FLOATING-POINT CONSTANTS
The ARM IAR Assembler will accept floating-point values as constants and convert
them into IEEE single-precision (signed 64-bit) floating-point format or fractional
format.
Floating-point numbers can be written in the format:
[+|-][digits].[digits][{E|e}[+|-]digits]
The following table shows some valid examples:
Format Value
10.23 1.023 x 101
1.23456E-24 1.23456 x 10-24
1.0E3 1.0 x 103
Table 4: Floating-point constants
PREDEFINED SYMBOLS
The ARM IAR Assembler defines a set of symbols for use in assembler source files.
The symbols provide information about the current assembly, allowing you to test
them in preprocessor directives or include them in the assembled code. The strings
returned by the assembler are enclosed in double quotes.
The following predefined symbols are available:
Symbol Value
__ARMVFP__ Identifies whether floating-point instructions for a vector
floating-point coprocessor have been enabled or not,
--fpu. Expands to the number 1 for VFPv1, and to the
number 2 for VFPv2. If floating-point instructions are
disabled (default), the symbol is undefined.
Table 5: Predefined symbols
AARM-7
Assembler expressions
Symbol Value
__BUILD_NUMBER__ A unique integer that identifies the build number of the
assembler currently in use. The build number does not
necessarily increase with an assembler that is released later.
__DATE__ Current date in dd/Mmm/yyyy format (string).
__FILE__ Current source filename (string).
__IAR_SYSTEMS_ASM__ IAR assembler identifier (number).
__LINE__ Current source line number (number).
__LITTLE_ENDIAN__ Identifies the byte order in use. Expands to the number 1
when the code is compiled with the little-endian byte order,
and to the number 0 when big-endian code is generated.
Little-endian is the default.
__SUBVERSION__ An integer that identifies the version letter of the version
number, for example the C in 4.21C, as an ASCII character.
__TID__ Target identity, consisting of two bytes (number). The high
byte is the target identity, which is 0x4F (=decimal 79) for
the ARM IAR Assembler. The low byte is not used.
__TIME__ Current time in hh:mm:ss format (string).
__VER__ Version number in integer format; for example, version
4.17 is returned as 417 (number).
Table 5: Predefined symbols (Continued)
In addition, predefined symbols are defined that allow you to identify the core you are
assembling for, for example __ARM5__ and __CORE__. For more details, see the
ARM® IAR C/C++ Compiler Reference Guide.
EXTERN printstr
DATA
tim DC8 __TIME__ ; time string
CODE32
ADR R0, tim ; load address of string
BL printstr ; routine to print string
END
AARM-7
Introduction to the ARM IAR Assembler
#ifdef __IAR_SYSTEMS_ASM__
...
#else
...
#endif
Register symbols
The following table shows the existing predefined register symbols:
Name Address size Description
R0–R12 32 bits General purpose registers
R13 (SP) 32 bits Stack pointer
R14 (LR) 32 bits Link register
R15 (PC) 32 bits Program counter
CPSR 32 bits Current program status register
SPSR 32 bits Saved process status register
Table 6: Predefined register symbols
In addition, specific cores may allow you to use other register symbols, for example
APSR for the Cortex-M3, if required by the instruction syntax.
Notice that only consecutive registers can be specified in register pairs. The upper odd
register should be entered to the left of the colon, and the lower even register to the
right.
Programming hints
This section gives hints on how to write efficient code for the ARM IAR Assembler.
For information about projects including both assembler and C/C++ source files, see
the ARM® IAR C/C++ Compiler Reference Guide.
AARM-7
Output formats
Example
The USART write address 0xFFFD0000 of the ARM7TDMI core is defined in the
ioat91m40400.h file as:
__IO_REG32_BIT(__US_CR,0xfffd0000,__WRITE,__usartcr_bits)
The declaration is converted by macros defined in the file io_macros.h to:
__US_CR DEFINE 0xfffd0000
If any assembler-specific additions are needed in the header file, these can be added
easily in the assembler-specific part of the file:
#ifdef __IAR_SYSTEMS_ASM__
(assembler-specific defines)
#endif
Output formats
The relocatable and absolute output is in the same format for all IAR assemblers,
because object code is always intended for processing with the IAR XLINK Linker.
In absolute formats the output from XLINK is, however, normally compatible with the
chip vendor’s debugger programs (monitors), as well as with PROM programmers
and stand-alone emulators from independent sources.
AARM-7
Assembler options
This chapter first explains how to set the options from the command line, and
gives an alphabetical summary of the assembler options. It then provides
detailed reference information for each assembler option.
The ARM® IAR Embedded Workbench® IDE User Guide describes how to set
assembler options in the IAR Embedded Workbench, and gives reference
information about the available options.
AARM-7
Setting assembler options
By default, extended command line files have the extension xcl, and can be specified
using the -f command line option. For example, to read the command line options
from extend.xcl, enter:
aarm -f extend.xcl
For example, setting the following environment variable will always generate a list
file with the name temp.lst:
ASMARM=-l temp.lst
For information about the environment variables used by the IAR XLINK Linker and
the IAR XLIB Librarian, see the IAR Linker and Library Tools Reference Guide.
AARM-7
Assembler options
11
AARM-7
Descriptions of assembler options
-B -B
Use this option to make the assembler print macro execution information to the
standard output stream on every call of a macro. The information consists of:
● The name of the macro
● The definition of the macro
● The arguments to the macro
● The expanded text of the macro.
This option is mainly used in conjunction with the list file options -L or -l; for
additional information, see page 16.
This option is identical to the Macro execution info option in the Assembler category
in the IAR Embedded Workbench.
-c -c{DMEAO}
Use this option to control the contents of the assembler list file. This option is mainly
used in conjunction with the list file options -L and -l; see page 16 for additional
information.
The following table shows the available parameters:
Command line option Description
This option is related to the List options in the Assembler category in the
IAR Embedded Workbench.
AARM-7
Assembler options
-D Dsymbol[=value]
Use this option to define a preprocessor symbol with the name symbol and the value
value. If no value is specified, 1 is used.
The -D option allows you to specify a value or choice on the command line instead of
in the source file.
Example
For example, you could arrange your source to produce either the test or production
version of your program dependent on whether the symbol testver was defined. To
do this, use include sections such as:
#ifdef testver
... ; additional code lines for test version only
#endif
Then select the version required in the command line as follows:
production version: aarm prog
test version: aarm prog -Dtestver
Alternatively, your source might use a variable that you need to change often. You can
then leave the variable undefined in the source, and use -D to specify the value on the
command line; for example:
aarm prog -Dframerate=3
This option is identical to the #define option in the Assembler category in the
IAR Embedded Workbench.
-E -Enumber
This option specifies the maximum number of errors that the assembler report will
report.
By default, the maximum number is 100. The -E option allows you to decrease or
increase this number to see more or fewer errors in a single assembly.
This option is identical to the Max number of errors option in the Assembler
category in the IAR Embedded Workbench.
13
AARM-7
Descriptions of assembler options
-e -e
This option causes the assembler to generate code and data in big-endian byte order.
The default byte order is little-endian.
This option is related to the Target options in the General Options category in the
IAR Embedded Workbench.
--endian --endian
This option specifies the byte order of the generated code and data.
-f -f extend.xcl
This option extends the command line with text read from the file named
extend.xcl. Notice that there must be a space between the option itself and the
filename.
The -f option is particularly useful where there is a large number of options which
are more conveniently placed in a file than on the command line itself.
Example
To run the assembler with further options taken from the file extend.xcl, use:
aarm prog -f extend.xcl
--fpu --fpu={VFPv1|VFPv2|VFP9-S|none}
Use the --fpu option to specify the target floating-point coprocessor to get the correct
instruction set.
The following parameters are available:
AARM-7
Assembler options
The --fpu option is automatically set if you use the --cpu option to select a target
core that has a floating-point unit.
-G -G
This option causes the assembler to read the source from the standard input stream,
rather than from a specified source file.
When -G is used, no source filename may be specified.
-I -Iprefix
Use this option to specify paths to be used by the preprocessor by adding the
#include file search prefix prefix.
By default, the assembler searches for #include files only in the current working
directory and in the paths specified in the AARM_INC environment variable. The -I
option allows you to give the assembler the names of directories where it will also
search if it fails to find the file in the current working directory.
Example
Using the options:
-Ic:\global\ -Ic:\thisproj\headers\
and then writing:
#include "asmlib.hdr"
in the source, will make the assembler search first in the current directory, then in the
directory c:\global\, and finally in the directory c:\thisproj\headers\
provided that the AARM_INC environment variable is set.
This option is related to the #include option in the Assembler category in the
IAR Embedded Workbench.
-i -i
Includes #include files in the list file.
By default, the assembler does not list #include file lines since these often come
from standard files and would waste space in the list file. The -i option allows you to
list these file lines.
This option is related to the #include option in the Assembler category in the
IAR Embedded Workbench.
15
AARM-7
Descriptions of assembler options
-j -j
Enables alternative register names, mnemonics, and operators in order to increase
compatibility with other assemblers and allow porting of code.
For additional information, see Operator synonyms, page 25, and the chapter
Migrating to the ARM IAR Assembler.
This option is identical to the Allow alternative register names, mnemonics and
operands option in the Assembler category in the IAR Embedded Workbench.
-L -L[prefix]
By default the assembler does not generate a list file. Use this option to make the
assembler generate one and sent it to file [prefix]sourcename.lst.
To simply generate a listing, use the -L option without a prefix. The listing is sent to
the file with the same name as the source, but the extension will be lst.
The -L option lets you specify a prefix, for example to direct the list file to a
subdirectory. Notice that you must not include a space before the prefix.
-L may not be used at the same time as -l.
Example
To send the list file to list\prog.lst rather than the default prog.lst:
aarm prog -Llist\
This option is related to the List options in the Assembler category in the
IAR Embedded Workbench.
-l -l filename
Use this option to make the assembler generate a listing and send it to the file
filename. If no extension is specified, lst is used. Notice that you must include a
space before the filename.
By default, the assembler does not generate a list file. The -l option generates a
listing, and directs it to a specific file. To generate a list file with the default filename,
use the -L option instead.
This option is related to the List options in the Assembler category in the
IAR Embedded Workbench.
AARM-7
Assembler options
-M -Mab
This option sets the characters to be used as left and right quotes of each macro
argument to a and b respectively.
By default, the characters are < and >. The -M option allows you to change the quote
characters to suit an alternative convention or simply to allow a macro argument to
contain < or > themselves.
Example
For example, using the option:
-M[]
in the source you would write, for example:
print [>]
to call a macro print with > as the argument.
Note: Depending on your host environment, it may be necessary to use quote marks
with the macro quote characters, for example:
aarm filename -M’<>’
This option is identical to the Macro quote chars option in the Assembler category
in the IAR Embedded Workbench.
-N -N
Use this option to omit the header section that is printed by default in the beginning of
the list file.
This option is useful in conjunction with the list file options -L or -l; see page 16 for
additional information.
This option is related to the List file option in the Assembler category in the
IAR Embedded Workbench.
-n -n
By default, multibyte characters cannot be used in assembler source code. If you use this
option, multibyte characters in the source code are interpreted according to the host
computer’s default setting for multibyte support.
Multibyte characters are allowed in C and C++ style comments, in string literals, and in
character constants. They are transferred untouched to the generated code.
17
AARM-7
Descriptions of assembler options
-O -Oprefix
Use this option to set the prefix to be used on the name of the object file. Notice that
you must not include a space before the prefix.
By default the prefix is null, so the object filename corresponds to the source filename
(unless -o is used). The -O option lets you specify a prefix, for example to direct the
object file to a subdirectory.
Notice that -O may not be used at the same time as -o.
Example
To send the object code to the file obj\prog.r79 rather than to the default file
prog.r79:
aarm prog -Oobj\
This option is related to the Output directories option in the General Options
category in the IAR Embedded Workbench.
-o -o filename
This option sets the filename to be used for the object file. Notice that you must
include a space before the filename. If no extension is specified, r79 is used.
The option -o may not be used at the same time as the option -O.
Example
For example, the following command puts the object code to the file obj.r79 instead
of the default prog.r79:
aarm prog -o obj
Notice that you must include a space between the option itself and the filename.
This option is related to the filename and directory that you specify when creating a
new source file or project in the IAR Embedded Workbench.
-p -plines
The -p option sets the number of lines per page to lines, which must be in the range
10 to 150.
AARM-7
Assembler options
This option is used in conjunction with the list options -L or -l; see page 16 for
additional information.
This option is identical to the Lines/page option in the Assembler category in the
IAR Embedded Workbench.
-r -r
The -r option makes the assembler generate debug information that allows a
symbolic debugger such as the IAR C-SPY Debugger to be used on the program.
To reduce the size and link time of the object file, the assembler does not generate debug
information by default.
Project>Options>Assembler >Output>Generate debug information
-S -S
The -S option causes the assembler to operate without sending any messages to the
standard output stream.
By default, the assembler sends various insignificant messages via the standard output
stream. Use the -S option to prevent this.
The assembler sends error and warning messages to the error output stream, so they
are displayed regardless of this setting.
-s -s{+|-}
Use the -s option to control whether the assembler is sensitive to the case of user
symbols:
Command line option Description
By default, case sensitivity is on. This means that, for example, LABEL and label
refer to different symbols. Use -s- to turn case sensitivity off, in which case LABEL
and label will refer to the same symbol.
This option is identical to the Case sensitive user symbols option in the Assembler
category in the IAR Embedded Workbench.
19
AARM-7
Descriptions of assembler options
-t -tn
By default the assembler sets 8 character positions per tab stop. The -t option allows
you to specify a tab spacing to n, which must be in the range 2 to 9.
This option is useful in conjunction with the list options -L or -l; see page 16 for
additional information.
This option is identical to the Tab spacing option in the Assembler category in the
IAR Embedded Workbench.
-U -Usymbol
Use the -U option to undefine the predefined symbol symbol.
By default, the assembler provides certain predefined symbols; see Predefined
symbols, page 5. The -U option allows you to undefine such a predefined symbol to
make its name available for your own use through a subsequent -D option or source
definition.
Example
To use the name of the predefined symbol _ _TIME_ _ for your own purposes, you
could undefine it with:
aarm prog -U _ _TIME_ _
This option is identical to the #undef option in the Assembler category in the
IAR Embedded Workbench.
-w -w[string][s]
By default, the assembler displays a warning message when it detects an element of
the source which is legal in a syntactical sense, but may contain a programming error;
see Assembler diagnostics, page 109, for details.
Use this option to disable warnings. The -w option without a range disables all
warnings. The -w option with a range performs the following:
Command line option Description
AARM-7
Assembler options
Example
To disable just warning 0 (unreferenced label), use the following command:
aarm prog -w-0
To disable warnings 0 to 8, use the following command:
aarm prog -w-0-8
This option is identical to the Warnings option in the Assembler category in the
IAR Embedded Workbench.
-x -x{DI2}
Use this option to make the assembler include a cross-reference table at the end of the
list file.
This option is useful in conjunction with the list options -L or -l; see page 16 for
additional information.
The following parameters are available:
Command line option Description
-xD #defines
-xI Internal symbols
-x2 Dual line spacing
Table 13: Including cross-references in assembler list file (-x)
21
AARM-7
Descriptions of assembler options
AARM-7
Assembler operators
This chapter first describes the precedence of the assembler operators, and
then summarizes the operators, classified according to their precedence.
Finally, this chapter provides reference information about each operator,
presented in alphabetical order.
Precedence of operators
Each operator has a precedence number assigned to it that determines the order in
which the operator and its operands are evaluated. The precedence numbers range
from 1 (the highest precedence, i.e. first evaluated) to 7 (the lowest precedence, i.e.
last evaluated).
The following rules determine how expressions are evaluated:
● The highest precedence operators are evaluated first, then the second highest
precedence operators, and so on until the lowest precedence operators are
evaluated.
● Operators of equal precedence are evaluated from left to right in the expression.
● Parentheses ( and ) can be used for grouping operators and operands and for
controlling the order in which the expressions are evaluated. For example, the
following expression evaluates to 1:
7/(1+(2*3))
UNARY OPERATORS – 1
+ Unary plus.
– Unary minus.
! Logical NOT.
~ Bitwise NOT.
LOW Low byte.
HIGH High byte.
BYTE1 First byte.
23
AARM-7
Summary of assembler operators
SHIFT OPERATORS – 4
>> Logical shift right.
<< Logical shift left.
AND OPERATORS – 5
&& Logical AND.
& Bitwise AND.
OR OPERATORS – 6
|| Logical OR.
| Bitwise OR.
XOR Logical exclusive OR.
^ Bitwise exclusive OR.
AARM-7
Assembler operators
COMPARISON OPERATORS – 7
=, == Equal.
<>, != Not equal.
> Greater than.
< Less than.
UGT Unsigned greater than.
ULT Unsigned less than.
>= Greater than or equal.
<= Less than or equal.
OPERATOR SYNONYMS
A number of operator synonyms have been defined for compatibility with other
assemblers. The operator synonyms are enabled by the option -j. For details, see the
chapter Migrating to the ARM IAR Assembler.
Operator synonym Operator Function
Note: The ARM operators and the operator synonyms may have different precedence.
For more information about the precedence of the operators and their synonyms, see
the following reference sections. See also the chapter Migrating to the ARM IAR
Assembler.
25
AARM-7
Descriptions of operators
Descriptions of operators
The following sections give detailed descriptions of each assembler operator. See
Assembler expressions, page 2, for related information.
* Multiplication (2).
* produces the product of its two operands. The operands are taken as signed 32-bit
integers and the result is also a signed 32-bit integer.
Examples
2*2 → 4
-2*2 → -4
Examples
+3 → 3
3*+2 → 6
+ Addition (3).
The + addition operator produces the sum of the two operands which surround it. The
operands are taken as signed 32-bit integers and the result is also a signed 32-bit
integer.
Examples
92+19 → 111
-2+2 → 0
-2+-2 → -4
AARM-7
Assembler operators
– Subtraction (3).
The subtraction operator produces the difference when the right operand is taken away
from the left operand. The operands are taken as signed 32-bit integers and the result
is also signed 32-bit integer.
Examples
92-19 → 73
-2-2 → -4
-2--2 → 0
/ Division (2).
/ produces the integer quotient of the left operand divided by the right operator. The
operands are taken as signed 32-bit integers and the result is also a signed 32-bit
integer.
Examples
9/2 → 4
-12/3 → -4
9/2*6 → 24
< evaluates to 1 (true) if the left operand has a lower numeric value than the right
operand.
Examples
-1 < 2 → 1
2 < 1 → 0
2 < 2 → 0
<= evaluates to 1 (true) if the left operand has a lower or equal numeric value to the
right operand.
Examples
1 <= 2 → 1
2 <= 1 → 0
1 <= 1 → 1
27
AARM-7
Descriptions of operators
<> evaluates to 0 (false) if its two operands are identical in value or to 1 (true) if its
two operands are not identical in value.
Examples
1 <> 2 → 1
2 <> 2 → 0
'A' <> 'B' → 1
=, == Equal (7).
= evaluates to 1 (true) if its two operands are identical in value, or to 0 (false) if its two
operands are not identical in value.
Examples
1 = 2 → 0
2 == 2 → 1
'ABC' = 'ABCD' → 0
> evaluates to 1 (true) if the left operand has a higher numeric value than the right
operand.
Examples
-1 > 1 → 0
2 > 1 → 1
1 > 1 → 0
>= evaluates to 1 (true) if the left operand is equal to or has a higher numeric value
than the right operand.
Examples
1 >= 2 → 0
2 >= 1 → 1
1 >= 1 → 1
AARM-7
Assembler operators
Use && to perform logical AND between its two integer operands. If both operands
are non-zero the result is 1; otherwise it is zero.
Note: The precedence of :LAND: is 8.
Examples
B’1010 && B’0011 → 1
B’1010 && B’0101 → 1
B’1010 && B’0000 → 0
Examples
B’1010 & B’0011 → B’0010
B’1010 & B’0101 → B’0000
B’1010 & B’0000 → B’0OOO
Examples
~ B’1010 → B’11111111111111111111111111110101
Examples
B’1010 | B’0101 → B’1111
B’1010 | B’0000 → B’1010
29
AARM-7
Descriptions of operators
Examples
B’1010 ^ B’0101 → B’1111
B’1010 ^ B’0011 → B’1001
BYTE1 takes a single operand, which is interpreted as an unsigned 32-bit integer value.
The result is the unsigned, 8-bit integer value of the lower order byte of the operand.
Examples
BYTE1 0xABCD → 0xCD
BYTE2 takes a single operand, which is interpreted as an unsigned 32-bit integer value.
The result is the middle-low byte (bits 15 to 8) of the operand.
Examples
BYTE2 0x12345678 → 0x56
BYTE3 takes a single operand, which is interpreted as an unsigned 32-bit integer value.
The result is the middle-high byte (bits 23 to 16) of the operand.
Examples
BYTE3 0x12345678 → 0x34
BYTE4 takes a single operand, which is interpreted as an unsigned 32-bit integer value.
The result is the middle-high byte (bits 23 to 16) of the operand.
AARM-7
Assembler operators
Examples
BYTE4 0x12345678 → 0x12
Use the DATE operator to specify when the current assembly began.
The DATE operator takes an absolute argument (expression) and returns:
Examples
To assemble the date of assembly:
today: DC8 DATE 5, DATE 4, DATE 3
HIGH takes a single operand to its right which is interpreted as an unsigned, 16-bit
integer value. The result is the unsigned 8-bit integer value of the higher order byte of
the operand.
Examples
HIGH 0xABCD → 0xAB
HWRD takes a single operand, which is interpreted as an unsigned, 32-bit integer value.
The result is the high word (bits 31 to 16) of the operand.
Examples
HWRD 0x12345678 → 0x1234
31
AARM-7
Descriptions of operators
LOW takes a single operand, which is interpreted as an unsigned, 32-bit integer value.
The result is the unsigned, 8-bit integer value of the lower order byte of the operand.
Examples
LOW 0xABCD → 0xCD
LWRD takes a single operand, which is interpreted as an unsigned, 32-bit integer value.
The result is the low word (bits 15 to 0) of the operand.
Examples
LWRD 0x12345678 → 0x5678
% produces the remainder from the integer division of the left operand by the right
operand. The operands are taken as signed 32-bit integers and the result is also a
signed 32-bit integer.
X % Y is equivalent to X-Y*(X/Y) using integer division.
Examples
2 % 2 → 0
12 % 7 → 5
3 % 2 → 1
Examples
! B’0101 → 0
! B’0000 → 1
AARM-7
Assembler operators
Examples
B’1010 || B’0000 → 1
B’0000 || B’0000 → 0
Syntax
SFB(segment [{+ | -} offset])
Parameters
segment The name of a relocatable segment, which must be defined before
SFB is used.
offset An optional offset from the start address. The parentheses are
optional if offset is omitted.
Description
SFB accepts a single operand to its right. The operand must be the name of a
relocatable segment.
The operator evaluates to the absolute address of the first byte of that segment. This
evaluation takes place at linking time.
Examples
NAME demo
RSEG CODE
start: DC16 SFB(CODE)
Even if the above code is linked with many other modules, start will still be set to
the address of the first byte of the segment.
Syntax
SFE (segment [{+ | -} offset])
33
AARM-7
Descriptions of operators
Parameters
segment The name of a relocatable segment, which must be defined before
SFE is used.
offset An optional offset from the start address. The parentheses are
optional if offset is omitted.
Description
SFE accepts a single operand to its right. The operand must be the name of a
relocatable segment. The operator evaluates to the segment start address plus the
segment size. This evaluation takes place at linking time.
Examples
NAME demo
RSEG CODE
;...
RSEG CONST
end: DC32 SFE(CODE)
Even if the above code is linked with many other modules, end will still be set to the
address of the last byte of the CODE segment plus one.
The size of the segment MY_SEGMENT can be calculated as:
SFE(MY_SEGMENT)-SFB(MY_SEGMENT)
Use << to shift the left operand, which is always treated as unsigned, to the left. The
number of bits to shift is specified by the right operand, interpreted as an integer value
between 0 and 32.
Examples
B’00011100 << 3 → B’11100000
B’00000111111111111 << 5 → B’11111111111100000
14 << 1 → 28
Use >> to shift the left operand, which is always treated as unsigned, to the right.
The number of bits to shift is specified by the right operand, interpreted as an integer
value between 0 and 32.
AARM-7
Assembler operators
Examples
B’01110000 >> 3 → B’00001110
B’1111111111111111 >> 20 → 0
14 >> 1 → 7
Syntax
SIZEOF segment
Parameters
segment The name of a relocatable segment, which must be defined
before SIZEOF is used.
Description
SIZEOF generates SFE-SFB for its argument, which should be the name of a
relocatable segment; i.e. it calculates the size in bytes of a segment. This is done when
modules are linked together.
Examples
NAME demo
RSEG CODE
size: DC16 SIZEOF CODE
sets size to the size of segment CODE.
UGT evaluates to 1 (true) if the left operand has a larger value than the right operand.
The operation treats its operands as unsigned values.
Examples
2 UGT 1 → 1
-1 UGT 1 → 1
35
AARM-7
Descriptions of operators
ULT evaluates to 1 (true) if the left operand has a smaller value than the right operand.
The operation treats its operands as unsigned values.
Examples
1 ULT 2 → 1
-1 ULT 2 → 0
Examples
B’0101 XOR B’1010 → 0
B’0101 XOR B’0000 → 1
AARM-7
Assembler directives
This chapter gives an alphabetical summary of the assembler directives. It then
describes the syntax conventions and provides detailed reference information
for each category of directives.
Summary of directives
The following table gives a summary of all the assembler directives.
Directive Description Section
37
AARM-7
Summary of directives
AARM-7
Assembler directives
39
AARM-7
Summary of directives
AARM-7
Assembler directives
Syntax conventions
In the syntax definitions the following conventions are used:
● Parameters, representing what you would type, are shown in italics. So, for
example, in:
ORG expr
expr represents an arbitrary expression.
● Optional parameters are shown in square brackets. So, for example, in:
END [expr]
the expr parameter is optional.
● An ellipsis indicates that the previous item can be repeated an arbitrary number of
times. For example:
PUBLIC symbol [,symbol] …
indicates that PUBLIC can be followed by one or more symbols, separated by
commas.
● Alternatives are enclosed in { and } brackets, separated by a vertical bar, for
example:
LSTOUT{+|-}
indicates that the directive must be followed by either + or -.
41
AARM-7
Module control directives
PARAMETERS
The following table shows the correct form of the most commonly used types of
parameter:
Parameter What it consists of
SYNTAX
END [label]
ENDMOD [label]
LIBRARY symbol [(expr)]
MODULE symbol [(expr)]
NAME symbol [(expr)]
PROGRAM symbol [(expr)]
RTMODEL key, value
PARAMETERS
expr Optional expression (0–255) used by the IAR compiler to encode
programming language, memory model, and processor configuration.
AARM-7
Assembler directives
label An expression or label that can be resolved at assembly time. It is output in the
object code as a program entry address.
symbol Name assigned to module, used by XLINK and XLIB when processing object
files.
DESCRIPTION
Terminating a module
Use ENDMOD to define the end of a module.
43
AARM-7
Module control directives
Examples
The following example defines three modules where:
● MOD_1 and MOD_2 cannot be linked together since they have different values for
runtime model foo.
● MOD_1 and MOD_3 can be linked together since they have the same definition of
runtime model bar and no conflict in the definition of foo.
● MOD_2 and MOD_3 can be linked together since they have no runtime model
conflicts. The value * matches any runtime model value.
MODULE MOD_1
RTMODEL "foo", "1"
RTMODEL "bar", "XXX"
...
ENDMOD
MODULE MOD_2
RTMODEL "foo", "2"
RTMODEL "bar", "*"
...
ENDMOD
MODULE MOD_3
AARM-7
Assembler directives
SYNTAX
EXTERN symbol [,symbol] …
MULTWEAK symbol [,symbol] …
PUBLIC symbol [,symbol] …
PUBWEAK symbol [,symbol] …
REQUIRE symbol [,symbol] …
PARAMETERS
symbol Symbol to be imported or exported.
DESCRIPTION
45
AARM-7
Symbol control directives
Importing symbols
Use EXTERN to import an untyped external symbol.
The REQUIRE directive marks a symbol as referenced. This is useful if the segment
part containing the symbol must be loaded for the code containing the reference to
work, but the dependence is not otherwise evident.
EXAMPLES
The following example defines a subroutine to print an error message, and exports the
entry address err so that it can be called from other modules. It defines print as an
external routine; the address will be resolved at link time.
MODULE error
EXTERN print
PUBLIC err
CODE16
PUSH {LR}
err ADR R0,msg
BL print
POP {PC}
DATA
msg DC8 "**Error **"
RET
END
AARM-7
Assembler directives
ARM, CODE32 Subsequent instructions are assembled as 32-bit (ARM) instructions. Labels
within a CODE32 area have bit 0 set to 0. Force 4-byte alignment.
CODE16 Subsequent instructions are assembled as 16-bit (Thumb) instructions, using
the traditional CODE16 syntax. Labels within a CODE16 area have bit 0 set
to 1. Force 2-byte alignment.
DATA Defines an area of data within a code segment, where labels work as in a
CODE32 area.
THUMB Subsequent instructions are assembled either as 16-bit Thumb instructions,
or as 32-bit Thumb-2 instructions if the specified core supports the
Thumb-2 instruction set. The assembler syntax follows the Unified
Assembler syntax as specified by Advanced RISC Machines Ltd.
Table 19: Mode control directives
SYNTAX
ARM
CODE16
CODE32
DATA
THUMB
DESCRIPTION
To change between the Thumb and ARM processor modes, use the CODE16/THUMB
and CODE32/ARM directives with the BX instruction (Branch and Exchange) or some
other instruction that changes the execution mode. The CODE16/THUMB and
CODE32/ARM mode directives do not assemble to instructions that change the mode,
they only instruct the assembler how to interpret the following instructions.
Always use the DATA directive when defining data in a Thumb code segment with
DC8, DC16, or DC32, otherwise labels on the data will have bit 0 set.
Note: Be careful when porting assembler source code written for other assemblers.
AARM always sets bit 0 on Thumb code labels (local, external or public). See the
chapter Migrating to the ARM IAR Assembler for details.
The assembler will initially be in CODE32/ARM mode, except if you specified a core
which does not support ARM mode. In this case, the assembler will initially be in
THUMB mode.
47
AARM-7
Mode control directives
EXAMPLES
AARM-7
Assembler directives
SYNTAX
ALIGNRAM align
ALIGNROM align [,value]
ASEG [start [(align)]]
ASEGN segment [:type], address
COMMON segment [:type] [(align)]
EVEN [value]
ODD [value]
ORG expr
RSEG segment [:type] [flag] [(align)]
STACK segment [:type] [(align)]
PARAMETERS
address Address where this segment part will be placed.
align Exponent of the value to which the address should be aligned, in the range 0
to 30. For example, align 1 results in word alignment 2.
49
AARM-7
Segment control directives
flag NOROOT
This segment part may be discarded by the linker even if no symbols in this
segment part are referred to. Normally all segment parts except startup
code and interrupt vectors should set this flag. The default mode is ROOT
which indicates that the segment part must not be discarded.
REORDER
Allows the linker to reorder segment parts. For a given segment, all segment
parts must specify the same state for this flag.
SORT
The linker will sort the segment parts in decreasing alignment order. For a
given segment, all segment parts must specify the same state for this flag.
start A start address that has the same effect as using an ORG directive at the
beginning of the absolute segment.
type The memory type, typically CODE, or DATA. In addition, any of the types
supported by the IAR XLINK Linker.
DESCRIPTION
AARM-7
Assembler directives
Aligning a segment
Use ALIGNROM to align the program location counter to a specified address boundary.
The expression gives the power of two to which the program counter should be
aligned.
The alignment is made relative to the segment start; normally this means that the
segment alignment must be at least as large as that of the alignment directive to give
the desired result.
51
AARM-7
Segment control directives
ALIGNROM aligns by inserting zero/filled bytes. The EVEN directive aligns the
program counter to an even address (which is equivalent to ALIGNROM 1) and the
ODD directive aligns the program counter to an odd address.
Use ALIGNRAM to align the program location counter to a specified address boundary.
The expression gives the power of two to which the program location counter should
be aligned. ALIGNRAM aligns by incrementing the program location counter; no data
is generated.
EXAMPLES
EXTERN main
ASEG
ORG 0 ; RESET vector address
CODE32
reset: B main
END
In this example, the data following the first RSEG directive is placed in a relocatable
segment called dataseg(2).
The code following the second RSEG directive is placed in a relocatable segment
called CODE:
ASEG
ORG 0
B main ; RESET vector
DATA
functable:
f1: DC32 subrtn
DC32 divrtn
AARM-7
Assembler directives
RSEG codeseg:CODE(2)
CODE32
main:
LDR R0,=f1 ; get address
LDR PC,[R0] ; jump to it
END
This example defines two 100-byte stacks in a relocatable segment called rpnstack:
STACK rpnstack
DATA
parms DC8 100
opers DC8 100
END
The data is allocated from high to low addresses.
Aligning a segment
This example starts a relocatable segment, moves to an even address, and adds some
data. It then aligns to a 64-byte boundary before creating a 64-byte table.
NAME align
RSEG dataseg (6) ; Start a relocatable data
; segment and verify that it
53
AARM-7
Value assignment directives
; is correctly aligned
DATA
target DS16 1 ; Target is on an even
ALIGNROM 6 ; Zero fill to a 64-byte
; boundary
results DS32 64 ; Create a 64-byte table
DS32
ALIGNROM 3 ; Align to an 8-byte boundary
ages DS32 64 ; Create another 64-byte table
END
SYNTAX
label = expr
label ALIAS expr
label ASSIGN expr
label DEFINE expr
label EQU expr
LIMIT expr, min, max, message
label SET expr
label SETA expr
label VAR expr
AARM-7
Assembler directives
PARAMETERS
expr Value assigned to symbol or value to be tested.
message A text message that will be printed when expr is out of range.
min, max The minimum and maximum values allowed for expr.
DESCRIPTION
55
AARM-7
Value assignment directives
EXAMPLES
Redefining a symbol
The following example uses SET to redefine the symbol cons in a loop to generate a
table of the first 8 powers of 3:
NAME table
cons SET 1
table: DATA
cr_tabl 4
END table
AARM-7
Assembler directives
In the following example the symbol value defined in module add1 is local to that
module; a distinct symbol of the same name is defined in module add2. The DEFINE
directive is used for declaring DAT for use anywhere in the file:
NAME add1
PUBLIC add12
CODE32
DAT DEFINE 1
value EQU 12
add12:
MOV R0, #value
ADD R0,R0, #DAT
MOV PC, LR ; Return
ENDMOD
NAME add2
PUBLIC add20
value EQU 20
add20:
MOV R0, #value
ADD R0,R0, #DAT
MOV PC, LR ; Return
END
The symbol DAT defined in module add12 is also available to module add20.
57
AARM-7
Conditional assembly directives
SYNTAX
IF condition
ELSE
ELSEIF condition
ENDIF
AARM-7
Assembler directives
PARAMETERS
condition One of the following:
DESCRIPTION
Use the IF, ELSE, and ENDIF directives to control the assembly process at assembly
time. If the condition following the IF directive is not true, the subsequent instructions
will not generate any code (i.e. it will not be assembled or syntax checked) until an
ELSE or ENDIF directive is found.
Use ELSEIF to introduce a new condition after an IF directive. Conditional assembler
directives may be used anywhere in an assembly, but have their greatest use in
conjunction with macro processing.
All assembler directives (except END) as well as the inclusion of files may be disabled
by the conditional directives. Each IF directive must be terminated by an ENDIF
directive. The ELSE directive is optional, and if used, it must be inside an
IF...ENDIF block. IF...ENDIF and IF...ELSE...ENDIF blocks may be nested
to any level.
EXAMPLES
59
AARM-7
Macro processing directives
If two macro-arguments are supplied then the first and second argument of the add
instruction are assumed to be the same:
main:
MOV R1, #0xF0
?add R1, 0xFF ;this
?add R1, R1, 0xFF ;and this
add R1, R1, #0xFF ;are the same as this
END
SYNTAX
ENDM
ENDR
EXITM
LOCAL symbol [,symbol] …
name MACRO [,argument] …
REPT expr
REPTC formal,actual
REPTI formal,actual [,actual] …
PARAMETERS
actual String to be substituted.
AARM-7
Assembler directives
expr An expression.
formal Argument into which each character of actual (REPTC) or each actual
(REPTI) is substituted.
DESCRIPTION
A macro is a user-defined symbol that represents a block of one or more assembler
source lines. Once you have defined a macro you can use it in your program like an
assembler directive or assembler mnemonic.
When the assembler encounters a macro, it looks up the macro’s definition, and inserts
the lines that the macro represents as if they were included in the source file at that
position.
Macros perform simple text substitution effectively, and you can control what they
substitute by supplying parameters to them.
Defining a macro
You define a macro with the statement:
macroname MACRO [,arg] [,arg] …
Here macroname is the name you are going to use for the macro, and arg is an
argument for values that you want to pass to the macro when it is expanded.
61
AARM-7
Macro processing directives
For example:
cmp_reg MACRO op
CMP op
ENDM
The macro can be called using the macro quote characters:
CODE32
cmp_reg <R3, R4>
END
You can redefine the macro quote characters with the -M command line option; see
-M, page 17.
AARM-7
Assembler directives
RSEG ICODE
DO_ADD MACRO
IF _args == 3
ADD \1,\2,\3
ELSE
ADD \1,\1,\2
ENDIF
ENDM
END
63
AARM-7
Macro processing directives
Repeating statements
Use the REPT...ENDR structure to assemble the same block of instructions a number
of times. If expr evaluates to 0 nothing will be generated.
Use REPTC to assemble a block of instructions once for each character in a string. If
the string contains a comma it should be enclosed in quotation marks.
Use REPTI to assemble a block of instructions once for each string in a series of
strings. Strings containing commas should be enclosed in quotation marks.
EXAMPLES
This section gives examples of the different ways in which macros can make
assembler programming easier.
AARM-7
Assembler directives
RSEG DATASEG
DATA
buffer DS8 512 ; Reserve a buffer of
; 512 bytes
RSEG CODESEG(2)
CODE32
main: BL play
done: B done
play:
LDR R1,=buffer ; Use R1 as pointer
; into buffer
LDR R2,=IO_PORT ; Use R2 as pointer
; to the port
LDR R3,=512 ; Buffersize in R3
ADD R3,R3,R1 ; R3 = one past the
; buffer loop:
LDRB R4,[R1],#1 ; Get byte data in R4,
; increment pointer
; into buffer
STRB R4,[R2] ; Write to the address
; pointed to by R2
CMP R1, R3 ; Compare R1 to the
; address
; one past the buffer
BNE loop ; NOT EQUAL --> repeat
MOV PC,LR ; return
END main
For efficiency we can recode this using a macro:
play: MACRO buf, size, port
LOCAL loop
65
AARM-7
Macro processing directives
RSEG DATASEG
DATA
buffer: DS8 512 ; Reserve a buffer of
; 512 bytes
RSEG CODESEG(2)
CODE32
main:
play buffer,512,IO_PORT
done: B done
END main
Notice the use of the LOCAL directive to make the label loop local to the macro;
otherwise an error will be generated if the macro is used twice, as the loop label will
already exist.
The following example assembles a series of calls to a subroutine plot to plot each
character in a string:
NAME signon
EXTERN plotc
CODE32
BL plotc
ENDR
END
AARM-7
Assembler directives
67
AARM-7
Macro processing directives
CODE32
PUBLIC main
main MOV R0, #0
REPTI a, base, count, init
LDR R1, =a
STRB R0, [R1, #0]
ENDR
B .
END main
AARM-7
Assembler directives
SYNTAX
COL columns
LSTCND{+ | -}
LSTCOD{+ | -}
LSTEXP{+ | -}
LSTMAC{+ | -}
LSTOUT{+ | -}
LSTPAG{+ | -}
LSTREP{+ | -}
LSTXRF{+ | -}
PAGE
PAGSIZ lines
PARAMETERS
columns An absolute expression in the range 80 to 132, default is 80
69
AARM-7
Listing control directives
DESCRIPTION
AARM-7
Assembler directives
EXAMPLES
The following example shows how LSTCND+ hides a call to a subroutine that is
disabled by an IF directive:
NAME lstcndtst
CODE32
EXTERN print
RSEG prom
debug SET 0
begin IF debug
BL print
ENDIF
LSTCND+
begin2 IF debug
BL print
NOP
ENDIF
END
71
AARM-7
Listing control directives
The following example shows the effect of LSTCOD- on the generated code by a DATA
directive:
NAME lstcodtst
DATA
AARM-7
Assembler directives
LSTMAC-
73
AARM-7
C-style preprocessor directives
SYNTAX
#define label text
#elif condition
#else
#endif
#error "message"
#if condition
AARM-7
Assembler directives
#ifdef label
#ifndef label
#include {"filename" | <filename>}
#message "message"
#undef label
PARAMETERS
condition One of the following:
DESCRIPTION
75
AARM-7
C-style preprocessor directives
Conditional directives
Use the #if...#else...#endif directives to control the assembly process at assembly
time. If the condition following the #if directive is not true, the subsequent
instructions will not generate any code (i.e. it will not be assembled or syntax checked)
until a #endif or #else directive is found.
All assembler directives (except for END) and file inclusion may be disabled by the
conditional directives. Each #if directive must be terminated by a #endif directive.
The #else directive is optional and, if used, it must be inside a #if...#endif block.
#if...#endif and #if...#else...#endif blocks may be nested to any level.
Use #ifdef to assemble instructions up to the next #else or #endif directive only
if a symbol is defined.
Use #ifndef to assemble instructions up to the next #else or #endif directive only
if a symbol is undefined.
Displaying errors
Use #error to force the assembler to generate an error, such as in a user-defined test.
AARM-7
Assembler directives
The following example illustrates some problems that may occur when assembler
comments are used in the C-style preprocessor:
EXAMPLES
The following example uses #ifdef to check that a certain symbol is defined and in
that case use two internally defined symbols. Otherwise, the same symbols are
declared EXTERN and a message displayed by #message. The STAND_ALONE symbol
can, for example, be defined on the command line via the -D option, see -D, page 13.
PROGRAM target
CODE32
PUBLIC main
#ifdef STAND_ALONE
alpha EQU 0x20
beta EQU 0x22
#else
EXTERN alpha, beta
#message "Program depends on additional link information"
#endif
main:
MOV R1,#alpha
MOV R2,#beta
ADD R2,R2,R1
EOR R1,R1,R2 ; R1 = (alpha XOR (alpha + beta))
END main
The following example uses #include to include a file defining macros into the
source file. For example, the following macros could be defined in macros.s79:
; exchange a and b using c as temporary
xch MACRO a,b, c
MOV c,a
77
AARM-7
Data definition or allocation directives
MOV a,b
MOV b,c
ENDM
The macro definitions can then be included by use of #include:
NAME include
; standard macro definitions
#include "macros.s79"
; program
main:
xch R0,R1,R2
END main
SYNTAX
DC8 expr [,expr] ...
DC16 expr [,expr] ...
DC24 expr [,expr] ...
DC32 expr [,expr] ...
AARM-7
Assembler directives
DCB expr[,expr]
DCD expr[,expr]
DCW expr[,expr]
DF32 constant[,constant]
DF64 constant[,constant]
DS16 expr [,expr] ...
DS24 expr [,expr] ...
DS32 expr [,expr] ...
DS8 expr [,expr] ...
PARAMETERS
expr A valid absolute, relocatable, or external expression, or an ASCII string. ASCII
strings will be zero filled to a multiple of the size. Double-quoted strings will be
zero-terminated.
DESCRIPTION
Use DC8, DC16, DC24, DC32, DCB, DCD, DCW, DF32, or DF64 to reserve and initialize
memory space.
Use DS8, DS16, DS24, or DS32 to reserve uninitialized memory space.
EXAMPLES
NAME table
CODE32
EXTERN add_f, sub_f, div_f, mul_f
ASEG
ORG 0
start B main ; RESET vector
RSEG DATASEG(2)
DATA
; pointer table to floating point
; routines
table: DC32 add_f, sub_f, div_f, mul_f
PI: DC32 3.1415927
79
AARM-7
Assembler control directives
RSEG CODESEG(2)
CODE32
main:
LDR R1, =PI ; Read up
; address to P1
LDR R2, =radius ; Do the same
; with radius...
LDR R0, =table ; Put base
; address to
; table in R0
LDR R0, [R0,#MUL_SELECTOR] ; Read address
; to mul_f from
; table
MOV PC,R0 ; goto mul_f
END main
Defining strings
To define a string:
mymsg DC8 'Please enter your name'
To define a string which includes a trailing zero:
myCstr DC8 "This is a string."
To include a single quote in a string, enter it twice; for example:
errmsg DC8 'Don''t understand!'
Reserving space
To reserve space for 0xA bytes:
table DS8 0xA
$ Includes a file.
/*comment*/ C-style comment delimiter.
Table 27: Assembler control directives
AARM-7
Assembler directives
Directive Description
SYNTAX
$filename
/*comment*/
//comment
CASEOFF
CASEON
INCLUDE filename
LTORG
RADIX expr
PARAMETERS
comment Comment ignored by the assembler.
DESCRIPTION
Use $ to insert the contents of a file into the source file at a specified point.
Use RADIX to set the default base for use in conversion of constants from ASCII
source to the internal binary format.
To reset the base from 16 to 10, expr must be written in hexadecimal format, for
example:
RADIX 0x0A
Use LTORG to direct the current literal pool to be assembled. This is done by default
at every END, ENDMOD, and RSEG directive.
81
AARM-7
Assembler control directives
Defining comments
Use /* ... */ to comment sections of the assembler listing.
Use // to mark the rest of the line as comment.
EXAMPLES
The following example uses $ to include a file defining macros into the source file.
For example, the following macros could be defined in mymacros.s79:
; exchange a and b using c as temporary
xch MACRO a,b, c
MOV c, a
MOV a, b
MOV b, c
ENDM
The macro definitions can be included with a $ directive, as
in:
NAME include
CODE32
$mymacros.s79
; program
main:
xch R0,R1,R2
END main
AARM-7
Assembler directives
Defining comments
The following example shows how /*...*/ can be used for a multi-line comment:
/*
Program to read serial input.
Version 4: 19.9.01
Author: mjp
*/
END
The immediate argument will then be interpreted as H'12.
When CASEOFF is set, label and LABEL are identical in the following example:
label NOP ; Stored as "LABEL"
BL LABEL
NOP
The following will generate a duplicate label error:
CASEOFF
label NOP
LABEL NOP ; Error, "LABEL" already defined
END
83
AARM-7
Call frame information directives
Directive Description
SYNTAX
The syntax definitions below show the syntax of each directive. The directives are
grouped according to usage.
AARM-7
Assembler directives
85
AARM-7
Call frame information directives
PARAMETERS
align The power of two to which the address should be aligned. The
allowed range for align is 0 to 31. As an example, the value 1 results
in alignment on even addresses since 21 equals 2. The default align
value is 0, except for segments of type CODE where the default is 1.
bits The size of the resource in bits.
cell The name of a frame cell.
cfa The name of a CFA (canonical frame address).
cfiexpr A CFI expression (see CFI expressions, page 92).
commonblock The name of a previously defined common block.
constant A constant value or an assembler expression that can be evaluated
to a constant value.
label A function label.
name The name of the block.
namesblock The name of a previously defined names block.
offset The offset relative the CFA. An integer with an optional sign.
part A part of a composite resource. The name of a previously declared
resource.
resource The name of a resource.
segment The name of a segment.
size The size of the frame cell in bytes.
type The memory type, such as CODE, CONST or DATA. In addition, any
of the memory types supported by the IAR XLINK Linker. It is used
solely for the purpose of denoting an address space.
DESCRIPTIONS
The Call Frame Information directives (CFI directives) are an extension to the
debugging format of the IAR C-SPY Debugger. The CFI directives are used to define
the backtrace information for the instructions in a program. The compiler normally
generates this information, but for library functions and other code written purely in
assembler language, backtrace information has to be added if you want to use the call
frame stack in the debugger.
AARM-7
Assembler directives
The backtrace information is used to keep track of the contents of resources, such as
registers or memory cells, in the assembler code. This information is used by the IAR
C-SPY Debugger to go “back” in the call stack and show the correct values of registers
or other resources before entering the function. In contrast with traditional
approaches, this permits the debugger to run at full speed until it reaches a breakpoint,
stop at the breakpoint, and retrieve backtrace information at that point in the program.
The information can then be used to compute the contents of the resources in any of
the calling functions—assuming they have call frame information as well.
87
AARM-7
Call frame information directives
The parameters are the name of the resource and the size of the resource in bits. A
virtual resource is a logical concept, in contrast to a “physical” resource such as a
processor register. Virtual resources are usually used for the return address.
More than one resource can be declared by separating them with commas.
A resource may also be a composite resource, made up of at least two parts. To
declare the composition of a composite resource, use the directive:
CFI RESOURCEPARTS resource part, part, …
The parts are separated with commas. The resource and its parts must have been
previously declared as resources, as described above.
● To declare a stack frame CFA, use the directive:
CFI STACKFRAME cfa resource type
The parameters are the name of the stack frame CFA, the name of the associated
resource (the stack pointer), and the segment type (to get the address space). More
than one stack frame CFA can be declared by separating them with commas.
When going “back” in the call stack, the value of the stack frame CFA is copied
into the associated stack pointer resource to get a correct value for the previous
function frame.
● To declare a static overlay frame CFA, use the directive:
CFI STATICOVERLAYFRAME cfa segment
The parameters are the name of the CFA and the name of the segment where the
static overlay for the function is located. More than one static overlay frame CFA
can be declared by separating them with commas.
● To declare a base address CFA, use the directive:
CFI BASEADDRESS cfa type
The parameters are the name of the CFA and the segment type. More than one base
address CFA can be declared by separating them with commas.
A base address CFA is used to conveniently handle a CFA. In contrast to the stack
frame CFA, there is no associated stack pointer resource to restore.
AARM-7
Assembler directives
89
AARM-7
Call frame information directives
where name is the name of the new extended block, commonblock is the name of the
existing common block, and namesblock is the name of a previously defined names
block. The extended block must end with the directive:
CFI ENDCOMMON name
SIMPLE RULES
To describe the tracking information for individual columns, there is a set of simple
rules with specialized syntax:
CFI cfa { NOTUSED | USED }
CFI cfa { resource | resource + constant | resource - constant }
CFI resource { UNDEFINED | SAMEVALUE | CONCAT }
CFI resource { resource | FRAME(cfa, offset) }
These simple rules can be used both in common blocks to describe the initial
information for resources and CFAs, and inside data blocks to describe changes to the
information for resources or CFAs.
AARM-7
Assembler directives
In those rare cases where the descriptive power of the simple rules are not enough, a
full CFI expression can be used to describe the information (see CFI expressions, page
92). However, whenever possible, you should always use a simple rule instead of a
CFI expression.
There are two different sets of simple rules: one for resources and one for CFAs.
91
AARM-7
Call frame information directives
This requires that at least one of the resource parts has a definition, using the rules
described above.
CFI EXPRESSIONS
Call Frame Information expressions (CFI expressions) can be used when the
descriptive power of the simple rules for resources and CFAs is not enough. However,
you should always use a simple rule when one is available.
CFI expressions consist of operands and operators. Only the operators described
below are allowed in a CFI expression. In most cases, they have an equivalent operator
in the regular assembler expressions.
In the operand descriptions, cfiexpr denotes one of the following:
● A CFI operator with operands
● A numeric constant
● A CFA name
AARM-7
Assembler directives
● A resource name.
Unary operators
Overall syntax: OPERATOR(operand)
Operator Operand Description
Binary operators
Overall syntax: OPERATOR(operand1,operand2)
Operator Operands Description
93
AARM-7
Call frame information directives
RSHIFTL cfiexpr,cfiexpr Logical shift right of the left operand. The number of
bits to shift is specified by the right operand. The sign
bit will not be preserved when shifting.
RSHIFTA cfiexpr,cfiexpr Arithmetic shift right of the left operand. The number
of bits to shift is specified by the right operand. In
contrast with RSHIFTL the sign bit will be preserved
when shifting.
Table 30: Binary operators in CFI expressions
Ternary operators
Overall syntax: OPERATOR(operand1,operand2,operand3)
Operator Operands Description
FRAME cfa,size,offset Get value from stack frame. The operands are:
cfa An identifier denoting a previously declared CFA.
size A constant expression denoting a size in bytes.
offset A constant expression denoting an offset in bytes.
Gets the value at address cfa+offset of size size.
IF cond,true,false Conditional operator. The operands are:
cond A CFA expression denoting a condition.
true Any CFA expression.
false Any CFA expression.
If the conditional expression is non-zero, the result is the
value of the true expression; otherwise the result is the
value of the false expression.
LOAD size,type,addr Get value from memory. The operands are:
size A constant expression denoting a size in bytes.
type A memory type.
addr A CFA expression denoting a memory address.
Gets the value at address addr in segment type type of
size size.
Table 31: Ternary operators in CFI expressions
EXAMPLE
The following is a generic example and not an example specific to the ARM core. This
will simplify the example and clarify the usage of the CFI directives. A target-specific
example can be obtained by generating assembler output when compiling a C source
file.
AARM-7
Assembler directives
Consider a generic processor with a stack pointer SP, and two registers R0 and R1.
Register R0 will be used as a scratch register (the register is destroyed by the function
call), whereas register R1 has to be restored after the function call. For reasons of
simplicity, all instructions, registers, and addresses will have a width of 16 bits.
Consider the following short code sample with the corresponding backtrace rows and
columns. At entry, assume that the stack contains a 16-bit return address. The stack
grows from high addresses towards zero. The CFA denotes the top of the call frame,
that is, the value of the stack pointer after returning from the function.
Address CFA SP R0 R1 RET Assembler code
Each backtrace row describes the state of the tracked resources before the execution
of the instruction. As an example, for the MOV R1,R0 instruction the original value of
the R1 register is located in the R0 register and the top of the function frame (the CFA
column) is SP + 2. The backtrace row at address 0000 is the initial row and the result
of the calling convention used for the function.
The SP column is empty since the CFA is defined in terms of the stack pointer. The
RET column is the return address column—that is, the location of the return address.
The R0 column has a ‘—’ in the first line to indicate that the value of R0 is undefined
and does not need to be restored on exit from the function. The R1 column has SAME
in the initial row to indicate that the value of the R1 register will be restored to the
same value it already has.
95
AARM-7
Call frame information directives
AARM-7
Assembler
pseudo-instructions
The ARM IAR Assembler accepts a number of pseudo-instructions, which are
translated into correct code. This chapter lists the pseudo-instructions and
gives examples of their use.
Summary
In the following table, as well as in the following descriptions, ARM denotes
pseudo-instructions available after the ARM directive, CODE16 denotes
pseudo-instructions available after the CODE16 directive, and THUMB denotes
pseudo-instructions available after the THUMB directive. Note that the properties of
THUMB pseudo-instructions depend on whether the used core has the Thumb-2
instruction set or not.
The following table shows a summary of the available pseudo-instructions:
Pseudo-instruction Directive Translated to Description
97
AARM-7
Descriptions of pseudo-instructions
LDR ARM MOV, MVN, LDR Loads a register with any 32-bit
expression.
LDR CODE16 MOV, LDR Loads a register with any 32-bit
expression.
LDR THUMB MOV, MVN, LDR Loads a register with any 32-bit
expression.
MOV CODE16 ADD Moves the value of a low register to
another low register (R0–R7).
MOV32 THUMB MOV, MOVT Loads a register with any 32-bit
value.
NOP ARM MOV Generates the preferred ARM
no-operation code.
NOP CODE16 MOV Generates the preferred Thumb
no-operation code.
Table 33: Pseudo-instructions (Continued)
Descriptions of pseudo-instructions
The following section gives reference information about each pseudo-instruction.
Parameters
{condition} Can be one of the following: EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE,
LT, GT, LE, and AL.
register The register to load.
Description
ADR always assembles to one instruction. The assembler attempts to produce a single
ADD or SUB instruction to load the address:
CODE32
ADR r0,thumb ; => ADD r0,pc,#1
AARM-7
Assembler pseudo-instructions
BX r0
CODE16
thumb
Parameters
register The register to load.
Description
In Thumb mode, ADR can generate word-aligned addresses only (i. e. addresses
divisible by 4). Use the ALIGNROM directive to ensure that the address is aligned
(unless DC32 is used, because it is always word aligned):
ADR r0,my_data ; => ADD r0,pc,#4
ADD r0,r0,r1
BX lr
DATA
ALIGNROM
my_data DC32 0xABCD19
Parameters
{condition} An optional condition code if the instruction is placed after an IT
instruction.
Description
Similar to ADR (CODE16), but the address range can be larger if a 32-bit Thumb-2
instruction is generated. If only 16-bit Thumb instructions are available, see ADR
(CODE16), page 99.
If the address offset is positive and the address is word-aligned, the 16-bit ADR
(CODE16) version will be generated by default.
99
AARM-7
Descriptions of pseudo-instructions
The 16-bit version can be specified explicitly with the ADR.N instruction. The 32-bit
version can be specified explicitly with the ADR.W instruction.
Parameters
{condition} Can be one of the following: EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE,
LT, GT, LE, and AL.
register The register to load.
Description
The ADRL pseudo-instruction loads a program-relative address into a register. It is
similar to the ADR pseudo-instruction. ADRL can load a wider range of addresses than
ADR because it generates two data processing instructions. ADRL always assembles to
two instructions. Even if the address can be reached in a single instruction, a second,
redundant instruction is produced. If the assembler cannot construct the address in two
instructions, it generates an error message and the assembly fails.
Note: ADRL is not available when assembling Thumb instructions. Use it only in ARM
code.
Example
ADRL r1,my_data+0x2345 ; => ADD r1,pc,#0x45
; => ADD r1,r1,#0x2300
DATA
my_data: DC32 0
Parameters
{condition} An optional condition code if the instruction is placed after an IT
instruction.
AARM-7
Assembler pseudo-instructions
Description
Similar to ADRL (ARM), but the address range can be larger. This instruction is only
available in a core supporting the Thumb-2 instruction set.
Parameters
{condition} An optional condition code if the instruction is placed after an IT
instruction.
Description
Similar to the _BLF (ARM)and _BLF (THUMB) instructions, respectively, but a B
instruction is generated instead of a BL instruction.
The _BF (THUMB) instruction is only available in a core supporting the Thumb-2
instruction set.
Parameters
condition An optional condition code.
Description
The instruction is used by the compiler when calling functions that may be far away
or in Thumb mode. If the first label is within range of a BL instruction, and is in ARM
mode, a BL instruction to that label is produced. Otherwise a BL instruction to the
second label is produced:
101
AARM-7
Descriptions of pseudo-instructions
Parameters
label1 Direct label.
Description
If the first label is within range of a BL instruction, and is in Thumb mode, a BL
instruction to that label is produced. Otherwise a BL instruction to the second label is
produced:
_BLF ext_fun,relay_fun
Parameters
{condition} An optional condition code if the instruction is placed after an IT
instruction.
Description
Similar to the _BLF (CODE16) instruction, but the address range for BL is larger in
Thumb-2 mode so the direct label has a higher chance of being selected.
If only 16-bit Thumb instructions are available, see _BLF (CODE16), page 102.
AARM-7
Assembler pseudo-instructions
Parameters
condition An optional condition code.
Description
The first form of the LDR pseudo-instruction loads a register with any 32-bit
expression. The second form of the instruction reads a 32-bit value from an address
specified by the expression. Note that there is also a true LDR instruction.
If the value of expression1 is within the range of a MOV or MVN instruction, the
assembler generates the appropriate instruction. If the value of expression1 is not
within the range of a MOV or MVN instruction, or if the expression1 is unsolved, the
assembler places the constant in a literal pool and generates a program-relative LDR
instruction that reads the constant from the literal pool. The offset from the program
location counter to the constant must be less than 4 Kbytes. See also the LTORG
directive in the section Assembler control directives, page 80, for more information.
Example
LDR r1,=0x12345678 ; => LDR r1,[pc,#4]
; loads 0x12345678 from the
; literal pool into r1
LDR r2,my_data ; loads 0xFFEEDDCC into r2
; => LDR r2,[pc,#-4]
DATA
my_data DC32 0xFFEEDDCC
LTORG
103
AARM-7
Descriptions of pseudo-instructions
Parameters
register The register to be loaded. LDR can access the low registers (R0–R7) only.
Description
As in ARM mode, the first form of the LDR pseudo-instruction in Thumb mode loads
a register with any 32-bit expression. The second form of the instruction reads a 32-bit
value from an address specified by the expression. However, the offset from the
program location counter to the constant must be positive and less than 1 Kbyte.
Example
LDR r1,=ext_label ; => LDR r1,[pc,#8]
; loads ext_label from the
; literal pool into r1
NOP
LDR r2,my_data ; loads 0xFFEEDDCC into r2
NOP ; => LDR r2,[pc,#0]
DATA
my_data DC32 0xFFEEDDCC
LTORG
AARM-7
Assembler pseudo-instructions
Parameters
condition An optional condition code if the instruction is placed after an IT
instruction.
Description
Similar to the LDR (CODE16) instruction, but by using a 32-bit instruction, a larger
value can be loaded directly with a MOV or MVN instruction without requiring the
constant to be placed in a literal pool.
If only 16-bit Thumb instructions are available, see LDR (CODE16), page 104.
By specifying a 16-bit version explicitly with the LDR.N instruction, a 16-bit
instruction is always generated. This may lead to the constant being placed in the
literal pool, even though a 32-bit instruction could have loaded the value directly using
MOV or MVN.
By specifying a 32-bit version explicitly with the LDR.W instruction, a 32-bit
instruction is always generated.
If you do not specify either .N or .W, the 16-bit LDR (CODE16) instruction will be
generated, unless Rd is R8-R15, which leads to the 32-bit variant being generated.
Note: The syntax LDR{condition} register, expression2, as described for
LDR (ARM) and LDR (CODE16), is no longer considered a pseudo-instruction. It is
part of the normal instruction set as specified in the Unified Assembler syntax from
Advanced RISC Machines Ltd.
105
AARM-7
Descriptions of pseudo-instructions
Parameters
Rd The destination register.
Description
The Thumb MOV pseudo-instruction moves the value of a low register to another low
register (R0-R7). The Thumb MOV instruction cannot move values from one low
register to another.
Note: The ADD immediate instruction generated by the assembler has the side-effect
of updating the condition codes.
The MOV pseudo-instruction uses an ADD immediate instruction with a zero immediate
value.
Note: This description is only valid when using the CODE16 directive. After the
THUMB directive, the interpretation of the instruction syntax is defined by the
Undefined Assembler syntax from Advanced RISC Machines Ltd.
Example
MOV r2,r3 ; generates the opcode for ADD r2,r3,#0
Parameters
condition An optional condition code if the instruction is placed after an IT
instruction.
Description
Similar to the LDR (THUMB) instruction, but will load the constant by generating a
pair of the MOV (MOVW) and the MOVT instructions.
This pseudo-instruction always generates two 32-bit instructions and it is only
available in a core supporting the Thumb-2 instruction set.
AARM-7
Assembler pseudo-instructions
Description
NOP generates the preferred ARM no-operation code:
MOV r0,r0
Description
NOP generates the preferred Thumb no-operation code:
MOV r8,r8
107
AARM-7
Descriptions of pseudo-instructions
AARM-7
Assembler diagnostics
This chapter describes the format of the diagnostic messages and explains how
diagnostic messages are divided into different levels of severity.
Message format
All diagnostic messages are issued as complete, self-explanatory messages. A typical
diagnostic message from the assembler is produced in the form:
filename,linenumber level[tag]: message
where filename is the name of the source file in which the error was encountered;
linenumber is the line number at which the assembler detected the error; level is
the level of seriousness of the diagnostic; tag is a unique tag that identifies the
diagnostic message; message is a self-explanatory message, possibly several lines
long.
Diagnostic messages are displayed on the screen, as well as printed in the optional list
file.
Severity levels
The diagnostic messages produced by the ARM IAR Assembler reflect problems or
errors that are found in the source code or occur at assembly time.
109
AARM-7
Severity levels
AARM-7
Migrating to the ARM IAR
Assembler
Assembly source code that was originally written for other assemblers can
also be used with the ARM IAR Assembler. The assembler option -j allows you
to use a number of alternative register names, mnemonics and operators.
This chapter contains information that is useful when migrating from an
existing product to the ARM IAR Assembler.
Introduction
The ARM IAR Assembler (AARM) was designed using the same look and feel as
other IAR assemblers, while still making it easy to translate source code written for
the TASM assembler from Advanced RISC Machines Ltd.
When the option -j (Allow alternative register names, mnemonics and operands)
is selected, the instruction syntax is the same in AARM as in TASM. Many features,
such as directives and macros, are, however, incompatible and cause syntax errors.
There are also differences in Thumb code labels that may cause problems without
generating errors or warnings. Be extra careful when you use such labels in situations
other than jumps.
Note: For new code, use the ARM IAR Assembler register names, mnemonics and
operators.
Example
CODE32
ADR R0,T+1
MOV R1,#T-.
DD DATA
111
AARM-7
Alternative register names
DCD T
CODE16
T NOP
Rewrite instructions like this to make them portable (i.e. have the same effect when
assembled using both AARM and TASM). Note that ADR is equivalent to an ADD with
PC.
CODE32
ADD R0,PC,#(T-.-8) :OR: 1
MOV R1,#(T-.) :AND: 0xFFFFFFFE
DD DATA
DCD T
CODE16
T NOP
A1 R0
A2 R1
A3 R2
A4 R3
V1 R4
V2 R5
V3 R6
V4 R7
V5 R8
V6 R9
V7 R10
SB R9
SL R10
FP R11
IP R12
Table 34: Alternative register names
AARM-7
Migrating to the ARM IAR Assembler
Alternative mnemonics
A number of mnemonics used by other assemblers will be translated by the ARM IAR
Assembler when the option -j is specified. These alternative mnemonics are allowed
in CODE16 mode only. The following table lists the alternative mnemonics:
Alternative mnemonic ARM IAR Assembler mnemonic
ADCS ADC
ADDS ADD
ANDS AND
ASLS LSL
ASRS ASR
BICS BIC
BNCC BCS
BNCS BCC
BNEQ BNE
BNGE BLT
BNGT BLE
BNHI BLS
BNLE BGT
BNLO BCS
BNLS BHI
BNLT BGE
BNMI BPL
BNNE BEQ
BNPL BMI
BNVC BVS
BNVS BVC
CMN{cond}S CMN{cond}
CMP{cond}S CMP{cond}
EORS EOR
LSLS LSL
Table 35: Alternative mnemonics
113
AARM-7
Operator synonyms
LSRS LSR
MOVS MOV
MULS MUL
MVNS MVN
NEGS NEG
ORRS ORR
RORS ROR
SBCS SBC
SUBS SUB
TEQ{cond}S TEQ{cond}
TST{cond}S TST{cond}
Table 35: Alternative mnemonics (Continued)
Refer to the ARM Architecture Reference Manual (Prentice-Hall) for full descriptions
of the mnemonics.
Operator synonyms
A number of operators used by other assemblers will be translated by the ARM IAR
Assembler when the option -j is specified. The following operator synonyms are
allowed in both ARM and Thumb modes:
Operator synonym ARM IAR Assembler operator
:AND: &
:EOR: ^
:LAND: &&
:LEOR: XOR
:LNOT: !
:LOR: ||
:MOD: %
:NOT: ~
:OR: |
:SHL: <<
:SHR: >>
Table 36: Operator synonyms
AARM-7
Migrating to the ARM IAR Assembler
Note: ARM IAR Assembler operators and operator synonyms have different
precedence levels. For further descriptions of the operators, see the chapter Assembler
operators, page 23.
Warning messages
Unless the option -j is specified, the ARM IAR Assembler will issue warning
messages when the alternative names are used, or when illegal combinations of
operands are encountered. The following sections list the warning messages:
115
AARM-7
Warning messages
AARM-7
Index
Index
A CASEOFF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
CASEON. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
AARM_INC (environment variable) . . . . . . . . . . . . . . . . . 10 CFI directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
absolute segments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 CODE16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
ADD (assembler instruction) . . . . . . . . . . . . . . . . . . . . . . . 98 CODE32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
ADD (CFI operator). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 COL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
addition (assembler operator). . . . . . . . . . . . . . . . . . . . . . . 26 comments, using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
addresses, loading into a register . . . . . . . . . . . . . . . . 98–100 COMMON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
ADR (ARM) (pseudo-instruction) . . . . . . . . . . . . . . . . . . . 98 conditional assembly. . . . . . . . . . . . . . . . . . . . . . . . . . . 58
ADR (CODE16) (pseudo-instruction) . . . . . . . . . . . . . . . . 99 See also C-style preprocessor directives
ADR (THUMB) (pseudo-instruction) . . . . . . . . . . . . . . . . 99 C-style preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
ADRL (ARM) (pseudo-instruction). . . . . . . . . . . . . . . . . 100 DATA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
ADRL (THUMB) (pseudo-instruction) . . . . . . . . . . . . . . 100 data definition or allocation . . . . . . . . . . . . . . . . . . . . . 78
ALIAS (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . 54 DCB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
alignment, of segments. . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 DCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ALIGNRAM (assembler directive) . . . . . . . . . . . . . . . . . . 49 DCW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ALIGNROM (assembler directive) . . . . . . . . . . . . . . . . . . 49 DC16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
:AND: (assembler operator). . . . . . . . . . . . . . . . . . . . . . . . 29 DC24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
AND (CFI operator). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 DC32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
architecture, ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix DC8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ARM (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 47 DEFINE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
_ _ARMVFP_ _ (predefined symbol) . . . . . . . . . . . . . . . . . 5 DF32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ASCII character constants . . . . . . . . . . . . . . . . . . . . . . . . . . 4 DF64 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ASEG (assembler directive). . . . . . . . . . . . . . . . . . . . . . . . 49 DS16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ASEGN (assembler directive) . . . . . . . . . . . . . . . . . . . . . . 49 DS24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
asm (file extension) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 DS32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ASMARM (environment variable) . . . . . . . . . . . . . . . . . . 10 DS8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
assembler control directives . . . . . . . . . . . . . . . . . . . . . . . . 80 ELSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
assembler diagnostics. . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 ELSEIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
assembler directives END. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
ALIAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 ENDIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
ALIGNRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 ENDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ALIGNROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 ENDMOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 ENDR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ASEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 EQU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
ASEGN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 EVEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
assembler control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 EXITM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ASSIGN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 EXPORT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
call frame information. . . . . . . . . . . . . . . . . . . . . . . . . . 83 EXTERN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
117
AARM-7
IF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 SET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
IMPORT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 SETA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
INCLUDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 STACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
labels, using. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
LIBRARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 symbol control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
LIMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
list file control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 THUMB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
LOCAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 value assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
LSTCND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 VAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
LSTCOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 #define. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
LSTEXP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 #elif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
LSTMAC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 #else. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
LSTOUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 #endif. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
LSTPAG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 #error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
LSTREP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 #if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
LSTXRF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 #ifdef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
LTORG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 #ifndef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
MACRO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 #include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
macro processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 #message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
MODULE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 #undef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
module control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 $. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
MULTWEAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 /*...*/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
NAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
ODD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
ORG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 assembler expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
PAGE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 assembler instructions
PAGSIZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 ADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 BL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101–102
PROGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 BX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
PUBLIC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 LDR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
PUBWEAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 MOV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
RADIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 MVN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
REPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 SUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
REPTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 assembler labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
REPTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 assembler directives, using with . . . . . . . . . . . . . . . . . . 41
REQUIRE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 defining and undefining . . . . . . . . . . . . . . . . . . . . . . . . 75
RSEG. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 format of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
RTMODEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 in Thumb code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
segment control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
AARM-7
Index
119
AARM-7
| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 assembler source files, including . . . . . . . . . . . . . . . . . 76, 82
|| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 assembler source format. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
~. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 assembler subversion number . . . . . . . . . . . . . . . . . . . . . . . 6
assembler options assembler symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
command line, setting . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 exporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
extended command file, setting. . . . . . . . . . . . . . . . . . . . 9 importing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 in relocatable expressions . . . . . . . . . . . . . . . . . . . . . . . . 2
typographic convention . . . . . . . . . . . . . . . . . . . . . . . . . . x local . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
-B. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 predefined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
-c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 undefining. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
-D. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 redefining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
-E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 assembly error messages . . . . . . . . . . . . . . . . . . . . . . . . . 109
-e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 assembly warning messages. . . . . . . . . . . . . . . . . . . . . . . 109
-endian. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
-f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 14 ASSIGN (assembler directive). . . . . . . . . . . . . . . . . . . . . . 54
-G. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 assumptions (programming experience) . . . . . . . . . . . . . . ix
-I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
-i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
-j . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 B
-L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 -B (assembler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
-l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 backtrace information, defining . . . . . . . . . . . . . . . . . . . . . 83
-M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 bitwise AND (assembler operator) . . . . . . . . . . . . . . . . . . 29
-N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 bitwise exclusive OR (assembler operator) . . . . . . . . . . . . 30
-n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 bitwise NOT (assembler operator) . . . . . . . . . . . . . . . . . . . 29
-O. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 bitwise OR (assembler operator) . . . . . . . . . . . . . . . . . . . . 29
-o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 BL (assembler instruction). . . . . . . . . . . . . . . . . . . . 101–102
-p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 _ _BUILD_NUMBER_ _ (predefined symbol) . . . . . . . . . . 6
-r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 BX (assembler instruction) . . . . . . . . . . . . . . . . . . . . . . . . 47
-S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 byte order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
-s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
-t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 BYTE1 (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . 30
-U. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 BYTE2 (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . 30
-v . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13–14 BYTE3 (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . 30
-w. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 BYTE4 (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . 30
-x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
assembler output format. . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
assembler output, including debug information. . . . . . . . . 19
C
assembler pseudo-instructions . . . . . . . . . . . . . . . . . . . . . . 97 -c (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
assembler source code, porting . . . . . . . . . . . . . . . . . . . . . 47 call frame information directives . . . . . . . . . . . . . . . . . . . . 83
case-sensitive user symbols . . . . . . . . . . . . . . . . . . . . . . . . 19
AARM-7
Index
121
AARM-7
ENDMOD (assembler directive) . . . . . . . . . . . . . . . . . . . . 42 formats
ENDR (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . 60 assembler output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
environment variables assembler source code. . . . . . . . . . . . . . . . . . . . . . . . . . . 1
AARM_INC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 fourth byte (assembler operator) . . . . . . . . . . . . . . . . . . . . 30
ASMARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 --fpu (assembler option). . . . . . . . . . . . . . . . . . . . . . . . . . . 14
:EOR: (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . 30 FRAME (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
EQ (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
EQU (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . . 54
equal (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . . 28 G
#error (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 74 -G (assembler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
error messages GE (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
maximum number, specifying. . . . . . . . . . . . . . . . . . . . 13 global value, defining. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
using #error to display. . . . . . . . . . . . . . . . . . . . . . . . . . 76 greater than or equal (assembler operator). . . . . . . . . . . . . 28
EVEN (assembler directive). . . . . . . . . . . . . . . . . . . . . . . . 49 greater than (assembler operator). . . . . . . . . . . . . . . . . . . . 28
EXITM (assembler directive). . . . . . . . . . . . . . . . . . . . . . . 60 GT (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
experience, programming. . . . . . . . . . . . . . . . . . . . . . . . . . ix
EXPORT (assembler directive) . . . . . . . . . . . . . . . . . . . . . 45
expressions. See assembler expressions
H
extended command line file (extend.xcl) . . . . . . . . . . . . 9, 14 header files, SFR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
EXTERN (assembler directive) . . . . . . . . . . . . . . . . . . . . . 45 header section, omitting from assembler list file . . . . . . . . 17
high byte (assembler operator). . . . . . . . . . . . . . . . . . . . . . 31
high word (assembler operator) . . . . . . . . . . . . . . . . . . . . . 31
F HIGH (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . 31
-f (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 14 HWRD (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . 31
false value, in assembler expressions . . . . . . . . . . . . . . . . . . 2
fatal errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
_ _FILE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . . 6
I
file extensions -I (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
asm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 -i (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
msa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 _ _IAR_SYSTEMS_ASM_ _ (predefined symbol). . . . . . . 6
r79 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 #if (assembler directive). . . . . . . . . . . . . . . . . . . . . . . . . . . 74
s79 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 IF (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
xcl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 14 IF (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
file types #ifdef (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 74
assembler source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 #ifndef (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . 74
extended command line. . . . . . . . . . . . . . . . . . . . . . . 9, 14 IMPORT (assembler directive) . . . . . . . . . . . . . . . . . . . . . 45
#include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 #include files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
filenames, specifying for assembler object file . . . . . . . . . 18 #include (assembler directive) . . . . . . . . . . . . . . . . . . . . . . 74
first byte (assembler operator) . . . . . . . . . . . . . . . . . . . . . . 30 include paths, specifying . . . . . . . . . . . . . . . . . . . . . . . . . . 15
floating-point constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 INCLUDE (assembler directive) . . . . . . . . . . . . . . . . . . . . 81
AARM-7
Index
123
AARM-7
modules, terminating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 ORG (assembler directive). . . . . . . . . . . . . . . . . . . . . . . . . 49
modulo (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . 32 output format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
MOV (assembler instruction). . . . . . . . . . . . . . . . . . . . . . 103
MOV (CODE16) (pseudo-instruction). . . . . . . . . . . . . . . 106
MOV (THUMB) (pseudo-instruction) . . . . . . . . . . . . . . . 106 P
msa (file extension) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 -p (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
MUL (CFI operator). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 PAGE (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 69
multibyte character support . . . . . . . . . . . . . . . . . . . . . . . . 17 PAGSIZ (assembler directive) . . . . . . . . . . . . . . . . . . . . . . 69
multiplication (assembler operator) . . . . . . . . . . . . . . . . . . 26 parameters
multi-module files, assembling . . . . . . . . . . . . . . . . . . . . . 43 in assembler directives . . . . . . . . . . . . . . . . . . . . . . . . . 42
MULTWEAK (assembler directive) . . . . . . . . . . . . . . . . . 45 typographic convention . . . . . . . . . . . . . . . . . . . . . . . . . . x
MVN (assembler instruction). . . . . . . . . . . . . . . . . . . . . . 103 porting assembler source code . . . . . . . . . . . . . . . . . . . . . . 47
precedence, of assembler operators . . . . . . . . . . . . . . . . . . 23
O _ _TIME_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
_ _VER_ _. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
-O (assembler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 preprocessor symbol, defining . . . . . . . . . . . . . . . . . . . . . . 13
-o (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 prerequisites (programming experience) . . . . . . . . . . . . . . ix
ODD (assembler directive). . . . . . . . . . . . . . . . . . . . . . . . . 49 processor configuration, specifying . . . . . . . . . . . . . . . 13–14
operands processor mode, directives . . . . . . . . . . . . . . . . . . . . . . . . . 47
format of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 program location counter (PLC) . . . . . . . . . . . . . . . . . . . 1, 4
in assembler expressions . . . . . . . . . . . . . . . . . . . . . . . . . 2 setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
operations, format of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 program modules, beginning . . . . . . . . . . . . . . . . . . . . . . . 43
operation, silent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 PROGRAM (assembler directive) . . . . . . . . . . . . . . . . . . . 42
operators. See assembler operators programming experience, required . . . . . . . . . . . . . . . . . . ix
option summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 programming hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
:OR: (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . . 29 pseudo-instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
OR (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 ADR (ARM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
AARM-7
Index
ADR (CODE16) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
ADR (THUMB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 S
ADRL (ARM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 -S (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
ADRL (THUMB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 -s (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
LDR (ARM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 second byte (assembler operator). . . . . . . . . . . . . . . . . . . . 30
LDR (CODE16) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 segment begin (assembler operator). . . . . . . . . . . . . . . . . . 33
LDR (THUMB). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 segment control directives . . . . . . . . . . . . . . . . . . . . . . . . . 49
MOV (CODE16) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 segment end (assembler operator) . . . . . . . . . . . . . . . . . . . 33
MOV (THUMB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 segment size (assembler operator) . . . . . . . . . . . . . . . . . . . 35
NOP (ARM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 segments
NOP (CODE16) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 absolute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
_BF (ARM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 aligning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
_BF (THUMB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 common, beginning. . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
_BLF (ARM). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 relocatable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
_BLF (CODE16). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 stack, beginning. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
_BLF (THUMB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 SET (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . . 54
PUBLIC (assembler directive) . . . . . . . . . . . . . . . . . . . . . . 45 SETA (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 54
PUBWEAK (assembler directive) . . . . . . . . . . . . . . . . . . . 45 SFB (assembler operator). . . . . . . . . . . . . . . . . . . . . . . . . . 33
SFE (assembler operator). . . . . . . . . . . . . . . . . . . . . . . . . . 33
125
AARM-7
symbols user symbols, case sensitive . . . . . . . . . . . . . . . . . . . . . . . . 19
exporting to other modules . . . . . . . . . . . . . . . . . . . . . . 46
predefined, in assembler . . . . . . . . . . . . . . . . . . . . . . . . . 5
predefined, in assembler macro. . . . . . . . . . . . . . . . . . . 62 V
user-defined, case sensitive . . . . . . . . . . . . . . . . . . . . . . 19 -v (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 13–14
See also assembler symbols value assignment directives . . . . . . . . . . . . . . . . . . . . . . . . 54
synonyms, of assembler operators . . . . . . . . . . . . . . . . . . . 25 values, defining temporary. . . . . . . . . . . . . . . . . . . . . . . . . 78
syntax VAR (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . . 54
assembler directives . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 _ _VER_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . . 6
See also assembler source format version, of assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
s79 (file extension) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
W
T -w (assembler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
-t (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
tab spacing, specifying in assembler list file . . . . . . . . . . . 20 disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
target core, specifying. See processor configuration
target processor, specifying . . . . . . . . . . . . . . . . . . . . . 13–14
TASM assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
X
temporary values, defining. . . . . . . . . . . . . . . . . . . . . . 55, 78 -x (assembler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
third byte (assembler operator) . . . . . . . . . . . . . . . . . . . . . 30 xcl (file extension) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 14
THUMB (assembler directive). . . . . . . . . . . . . . . . . . . . . . 47 XOR (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . . 36
_ _TID_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 6–7 XOR (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
_ _TIME_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 6
time-critical code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii
Symbols
! (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
true value, in assembler expressions . . . . . . . . . . . . . . . . . . 2
!= (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
typographic conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . x
#define (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . 74
#elif (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . . 74
U #else (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . . 74
#endif (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 74
-U (assembler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
UGT (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . . 35 #error (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 74
ULT (assembler operator) . . . . . . . . . . . . . . . . . . . . . . . . . 36 #if (assembler directive). . . . . . . . . . . . . . . . . . . . . . . . . . . 74
UMINUS (CFI operator) . . . . . . . . . . . . . . . . . . . . . . . . . . 93 #ifdef (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 74
unary minus (assembler operator) . . . . . . . . . . . . . . . . . . . 26 #ifndef (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . 74
unary plus (assembler operator) . . . . . . . . . . . . . . . . . . . . . 26 #include files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
#undef (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . 74 #include (assembler directive) . . . . . . . . . . . . . . . . . . . . . . 74
unsigned greater than (assembler operator) . . . . . . . . . . . . 35 #message (assembler directive) . . . . . . . . . . . . . . . . . . . . . 74
unsigned less than (assembler operator) . . . . . . . . . . . . . . 36 #undef (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . 74
AARM-7
Index
127
AARM-7