AVR Assembler v. 2.0: Addendum To On-Line Help
AVR Assembler v. 2.0: Addendum To On-Line Help
AVR Assembler v. 2.0: Addendum To On-Line Help
0
Addendum to on-line help
Beta 3 – 2004-07-07
1 INTRODUCTION.................................................................................................... 4
1.2 Support................................................................................................................................4
2 PACKAGE CONTENTS......................................................................................... 4
3 INSTALLATION...................................................................................................... 4
3.1 Uninstallation..................................................................................................................... 5
4 WHAT'S NEW......................................................................................................... 5
5 KNOWN ISSUES.................................................................................................... 6
6 INVOCATION SYNTAX.......................................................................................... 6
7.1 Keywords............................................................................................................................ 8
7.1.1 Instructions.................................................................................................................... 8
7.1.2 Registers........................................................................................................................9
7.1.3 Built-in functions and variables.................................................................................... 9
7.1.4 Assembler directives..................................................................................................... 9
8 PREPROCESSOR.................................................................................................. 9
8.3 Pragmas.............................................................................................................................11
9.1 Comments......................................................................................................................... 12
9.1.1 Preprocessor note........................................................................................................ 12
9.3 Instructions....................................................................................................................... 13
9.4 Labels................................................................................................................................ 13
9.5 Expressions....................................................................................................................... 13
10.1 Include.............................................................................................................................14
10.2 Conditionals....................................................................................................................14
10.3 Macros.............................................................................................................................14
10.4 Comments....................................................................................................................... 15
This information will be added to the on-line help when AVRASM2 is officially released.
It is fully backwards compatible with version 1.x (AVRASM), with a few minor exceptions
that are detailed in chapter 2. It also offers a number of new powerful features, including:
· C-style preprocessing directives like #define, #ifdef, etc. This also includes the
capability to control definition/undefinition of preprocessor symbols and inclusion of files
from the command line.
· Improved error detection and diagnostic messages, including exceeding available SRAM
and EEPROM memory ranges.
· Support for floating point constant expressions and conversion to fractional numbers as
used with the FMUL/FMUS/FMULSU instructions.
· Resource use statistics, including instructions, registers, and memory.
· Externalizing of device support, meaning support for new devices may be added without
having to upgrade the assembler executable.
1.2 Support
This is a BETA release, and as such not supported via the normal ATMEL support channels.
However, users may send feedback and bug reports directly to the developers, using the e-mail
address avrbeta@atmel.com.
The AVR Studio 4 forum at http://www.avrfreaks.com is also a suitable channel for providing
feedback or discussing this release.
2 Package contents
The following files are found at the download site:
3 Installation
Download the file AvrAssembler2.exe, run it, and follow instructions.
The assembler is configured by selecting Project – AVR Assembler Setup from the Studio
menubar.
The upper part of this window is the same as for AVR Assembler 1. The lower part enables
AVRASM2-Beta. The “Additional Parameters” field is used to add additional command-line
parameters for AVRASM2. (Hint: Try adding –vs , see section 5 for explanation.)
3.1 Uninstallation
This add-on package cannot be uninstalled, but unselecting Use AVR Assembler 2.0 beta
above will have the same effect, causing the standard 1.7x version to be used.
4 What's New
4.1 Changes in Beta 3
Bugs fixed:
• Macro argument expansion problem
• Preprocessor expression evaluation fails with multiple references to same macro.
• Preprocessor stack overflow caused by indirectly self-referencing macro.
• Comments in #define only work using C comments (Documentation issue)
The issues mentioned in this section will be fixed in a later AVRASM2 release.
AVRASM2 may produce one or both of the following warnings, depending on the device
used:
These definitions - the Zero (Z) flag in the status register and a deprecated flag in the UCSRA
register (use DOR instead of OR) will be renamed/removed from the .inc files.
As the warnings state, these definitions are ignored by AVRASM2. Any program not actually
using these definitions will be fine.
Programs using these definitions cannot be assembled successfully, and will need to be
changed.
6 Invocation syntax
The invocation syntax is shown below, new options are bold and described below.
Options:
-f [O|M|I|G|E] output file format:
-fO Debug info for simulation in AVR Studio (default)
-fM Motorola hex
-fI Intel hex
-fG Generic hex format
-o ofile Put output in 'ofile'.
-d dfile Generate debug info for simulation in AVR Studio in 'dfile'.
Can only be used with the -f [M|I|G] option.
-l lfile Generate listing in 'lfile'
-m mfile Generate map in 'mfile'
-e efile Place EEPROM contents in 'efile'
-w Relative jumps are allowed to wrap for program ROM
up to 4k words in size [ignored]
-C ver Specify AVR core version
-c Case sensitive
-1/-2 Turn on/off AVR Assembler version 1 compatibility.
-I dir Preprocessor: Add 'dir' to include search path
-i file Preprocessor: Explicitly pre-include file
-w
Wrap relative jumps. This option is obsoleted. It is still recognized by the assembler, but
ignored. The assembler will determine if wrapping is required based on flash memory size. If
the flash size is unknown, wrap will be disabled.
-C core-version
Specify AVR Core version. The core version is normally specified in part definition files
(partdef..inc), this option is intended for testing of the assembler, and generally not useful for
end-users.
-c
Causes the assembler to become entirely case sensitive. Preprocessor directives and macros
are always case sensitive. Warning: Setting this option will break many existing projects.
-1
-2
Enable and disable AVRASM1 compatibility mode. As of BETA 1, this option is enabled by
default (warning about this is printed). The default setting will be changed at a later time, and
this option may be removed altogether. The compatibility mode will permit certain constructs
otherwise considered errors, reducing the risk of breaking existing projects.
-i file
Include a file. #include “file” directive is processed before the first source code line is
processed. Multiple –i directives may be used and are processed in order.
-D name[=value]
-U name
Define and undefine a preprocessor macro, respectively.
Note that function-type preprocessor macros may not be defined from the command line.
-vs
Print use statistics for register, instruction and memory on standard output. By default, only
the memory statistic is printed. Note: The full statistics will always be printed to the list file, if
one is specified.
-vl
This will print the raw instructions emitted to stdout, after all symbolic info is replaced.
Mainly for assembler debugging purposes.
-v0
Print error messages only, warning and info messages are suppressed.
AVR Assembler 2.0 Page 7 of 16 Revision: BETA 3
© 2004 ATMEL Corp.
-v1
Print error and warning messages only, info messages are suppressed.
-v2
Print error, warning, and info messages. This is the default behaviour.
EXAMPLE
The following nonsensical and rather obfuscated program assembles without errors
with AVRASM1, but is incorrect with AVRASM2:
Assembler keywords are recognized regardless of case, unless the case-sensitive option is
used (see section 5). If the case-sensitive option is used, assembler keywords will have the
case shown here (generally lower case).
7.1.1 Instructions
7.1.2 Registers
r0 r1 r2 r3 r4 r5 r6 r7
r8 r9 r10 r11 r12 r13 r14 r15
r16 r17 r18 r19 r20 r21 r22 r23
r24 r25 r26 r27 r28 r29 r30 r31
x y z
Assembler directives are recognized by the fact that they start with a period (‘.’). Any word
preceded with a period will be attempted parsed as a directive.
There are no restrictions on the directive words without the leading period, nothing prevents
the user from defining symbols like 'if' or 'byte'.
The list of directives is given here for the sake of completeness, not because the directives
cause any problems:
8 Preprocessor
http://www.delorie.com/gnu/docs/gcc/cpp_toc.html
The AVRASM2 preprocessor may largely be expected to work as described in this reference,
unless otherwise explicitly stated.
‘#’ above is the empty directive (does nothing). The defined keyword is only used in
conjunction with #if statements, ie. #if defined
Note
Only C-style comments (/* ... */ or // ... ) are recognized by the preprocessor. Attempting to
use assembler comment syntax (; ...) in preprocessor directives may give surprises.
8.2.1 #define
1.#define name [value]
2.#define name(arg, ...) [value]
Note: Variadic macros (i.e., macros with variable number of arguments) are not implemented.
8.2.2 #undef
#undef name
8.2.3 #ifdef
#ifdef name
8.2.4 #ifndef
#ifndef name
8.2.6 #else
#else
8.2.7 #endif
#endif
8.2.8 #error/#warning/#message
#error tokens
#warning tokens
#message tokens
Unlike the GNU C preprocessor, the #error, #warning, and #message directives will
expand unquoted preprocessor macros. Example:
8.2.9 #include
1.#include "file"
2.#include <file>
Note: Computed #include is not implemented (i.e., using a macro to specify an include file
name)
8.2.10 #pragma
#pragma tokens
8.3 Pragmas
Pragmas are used to specify part-specific properties, normally set up in include files.
Normally there is no reason to use pragmas in user programs.
Notes
• The string values here are not quoted, and that the numeric values must be pure numbers (expressions or
preprocessor macros not allowed here).
• Everything in the #pragma directive is case sensitive.
• Distinguishing between variants of the same instruction based on operands only works for instructions that are
implemented with different operands in different variants on different AVR Core versions., presently these
are the ld, st, and lpm instructions.
Part-dependent:
__partname__ partname corresponds to the value of __PART_NAME__ above.
The preprocessor only recognizes C-style comments. The semicolon (;) is not treated in any special way in
preprocessor directives and this may have unexpected effects.
To avoid surprises, C-style comments should be used exclusively in lines with prepocessor directives.
Examle:
These definitions will result in FOO having the value "42 ; The foobaristic constant", while BAR simply has the
value "43". This may or may not be a problem depending on how FOO is used.
9.3 Instructions
Instructions take the following forms:
mnemonic
mnemonic operand
mnemonic operand, operand2
Allowed operands are registers r0-r31, x, y, z, x+, y+, z+, -x, -y, -z, and integer expressions
including preprocessor macros, constants defined with assembler directives, labels, and
functions.
9.4 Labels
A label is a user symbol followed by a colon (:). It may prepend an instruction or directive on
the same line or be placed on a separate line.
9.5 Expressions
Constant expressions can be integer or floating point, and follow the C rules for operator
precedence and type propagation. Symbols and instruction operands are always integer, a
suitable conversion function should be used to convert before assignment (eg, int(), q7()).
Implicit float→int conversion cause a warning and the fractional part is discarded.
Character constants can be used anywhere an integer expression is allowed, and the following
C-style escape sequences are recognized, with the same meaning as in C:
Examples:
Additonally, the forms $hhhh and 0bdddd are recognized as hexadecimal and binary integers,
respectively. These forms are also recognized and evaluated by the preprocessor.
10.1 Include.
#include and .include are identical, except that #include also supports the
'#include <file>' form.
10.2 Conditionals.
Preprocessor conditionals (#if, etc) relate to preprocessor symbols only (defined with #define
or the -D command-line option).
Assembler conditional relate to both preprocessor and assembler symbols, but beware of
unexpected effects:
#define FOO 2
...
.ifdef FOO
is a syntax error, because the assembler will try to evaluate '.ifdef 2'.
Avoid mixing the two forms! Preprocessor macros may be defined from the command line, and
this gives considerable flexibility.
10.3 Macros
Both the preprocessor and the assembler offer macros, but they work very differently and
should not be intermixed.
.macro pushw
push @0L
push @0H
.endmacro
Each line of the macro body remains a separate line after expansion. Labels in the macro body
have scope limited to the macro body.
pushw z
#define pushw(wreg) \
push wreg##L \
push wreg##H
(Note: the preprocessor concatenation operator ## is not yet implemented in BETA 1.)
Labels defined in a preprocessor macro have global scope, and the entire macro body becomes
one single line after expansion.
pushw(z)
10.4 Comments
The preprocessor only recognizes C-style comments (/*....*/, //....).
Assembler comments should not be used in conjunction with preprocessor directives. If
assembler comments are used in conjunction with #define directives, the comment will
become part of the macro, which may cause surprises when the macro is expanded.
Undefines a register definition created with the .def directive. Use this to avoid “already
defined by the .DEF directive” warnings.
These directives are similar to the .dw directive, except they are used to define doublewords
(32-bit) and quadwords (64-bit), respectively. The byte and word ordering is strictly little-
endian.
frac()
Extracts fractional part of a floating point expression (ie discards integer part).
q7()
Converts a fractional floating point expression to a form suitable for the
FMUL/FMULS/FMULSU instructions. (sign + 7-bit fraction)
q15()
Converts a fractional floating point to the form returned by the FMUL/FMULS/FMULSY
instructions (sign + 15-bit fraction).
abs()
Returns the absolute value of a constant expression.