AVRA(1) | User Commands | AVRA(1) |
avra - assembler for the AVR microcontroller family
avra [OPTION]... FILE
AVRA is an advanced macro assembler for the AVR microcontrollers designed as a replacement for AVRASM32. While command line options have been adapted as close as possible, AVRA offers a number of advanced features which are not present in the AVRASM32. These features should help in creating versatile and more modular code.
To compile a source file, run `avra mysource.S`. You will end up with a compiled version of the file in Intel HEX format at `mysource.S.hex`. You can control the output filename with `-o`. See `--help` for more options (not all options work).
There is a possibility to suppress certain warnings. Currently only register reassignment warnings can be suppressed:
AVRA offers a number of directives that are not part of Atmel's assembler. These directives should help you in creating versatile and more modular code.
Directive `.define`:
To define a constant, use `.define`. This does the same thing as `.equ`; it is just a little more C style. Keep in mind that AVRA is not case sensitive. The `.define` directive is not to be confused with `.def`, which is used to assign registers only. This is due to backward compatibility with Atmel's AVRASM32. Here is an example on how `.define` can be used:
Now `network` is set to the value 1. You can also define names without values:
Both versions are equivalent, as AVRA will implicitly define `network` to be 1 in the second case. (Although, if you really want `network` to be 1, you should use the first version.) You may want to assemble a specific part of your code depending on a define or switch setting. You can test your defined word on existence (`.ifdef` and `.ifndef`) as well as on the value it represents. The following code shows a way to prevent error messages due to testing undefined constants:
Directives `.if` and `.else`:
The three lines in the last example set the default value of `network`. Now we could use the `.if` and `.else` directives test whether, e.g., network support is to be included into the assembly process:
There is also an `.elif` ("else if") directive, which does what you think.
Directive `.error`:
The `.error` directive can be used to throw an error during the assembly process. The following example shows how we can stop the assembler if a particular value has not been previously set:
Directives `.nolist` and `.list`:
The output to the list file can be paused and resumed by the `.nolist` and `.list` directives. After AVRA discovers a `.nolist` while assembling, it stops output to the list file. After a `.list` directive is detected, AVRA continues the normal list file output.
Directive `.includepath`:
By default, any file that is included from within the source file must either be a single filename or an absolute path. With the directive `.includepath` you can set an additional include path. Furthermore, you can set as many include paths as you want. To avoid ambiguity, be sure not to use the same filename in separate included directories.
To avoid multiple inclusion of include files, you can use some directives, as shown in the following example:
You can use some special tags that AVRA supports to implement compiler build time and date into your program:
For example, these tags can be used as follows:
This line will then be assembled by AVRA into:
As another example, you can create an automatically-updating serial number with meta tags:
The `%TAG%` is translated before any other parsing happens. The real output can be found in the list file.
Sometimes you have to work with 16 bit or greater variables stored in 8 bit registers. AVRA provides enhanced macro support that allows you to write short and flexible macros that simplify access to big variables. The enhanced macro features are active when you use square brackets [ ] to wrap macro parameters. See the following examples.
Automatic Type Conversion For Macros:
Values representing more than 8 bits are usually kept in a set of byte wide registers. To simplify 16 bit operations, words can be written as `r16:r17`. In this example, `r16` contains the most significant byte and register `r17` contains the least significant byte. In the same way, a 24 bit value stored across 3 registers can be written as `r16:r17:r18`, for example (in this case, `r16` is the most significant and `r18` is the least significant). In fact, up to 8 registers can be used with this syntax.
Macro Data Types:
There are 3 data types that can be used in macro definitions. The data types are specified by appending one of the following codes that start with an underscore to the end of a macro name:
See the following section for examples on how these types work.
Within square brackets, the two words `src` and `dst` are interpreted as `YH:YL` and `ZH:ZL`, respectively. Normal code outside of the macro parameter square brackets can still make use of the special key words `src` and `dst` without any side effects.
Examples For Automatic Type Conversion and Macro Overloading:
To simplify the examples below, we redefine some registers:
If we subtract the 16 bit value `c:d` from `a:b`, we usually have to use the following command sequence:
Now we can use macros to simplify subtraction with 16 bit values:
Note that we have essentially overloaded the `subs` macro to accept arguments of different types, just like you could do in C, for example. Another example of macro overloading follows.
More Examples:
Loops Within Macros:
One problem you may have experienced is that labels defined within macros are defined twice, for example, if you call the macro two times. You can use labels for macro loops by appending "_%" to the label. The "%" symbol is replaced by a running number.
Loop Example:
Here are some frequently asked questions about common errors.
Constant Out of Range:
This warning occurs if a value exceeds the byte or word value of a assignment. Read the comment posted by Jim Galbraith:
The expression (~0x80) is a Bitwise Not operation. This operator returns the input expression with all its bits inverted. If 0x80 represents -128, then 0x7f, or +127 should be ok. If this is considered as a 32-bit expression (AVRA internal representation), then it appears to be more like oxffffffff-0x80 or 0xffffffff^0x80. The result would then be 0xffffff7f. The assembler would then have to be told or it would have to decide, based on context, how much significance to assign to the higher bits. I have also encountered such conditions with various assemblers, including AVRA. To make sure the assembler does what I really want, I use a construct like 0xff-0x80 or 0xff^0x80. This way the bit significance cannot extend beyond bit-7 and there cannot be any misunderstanding.
Can't Use `.DB` Directive in Data Segment:
The `.DB` and `.DW` directives are only used to assign constant data in the eeprom or code space. Using these directives within the data segment is forbidden because you cannot set ram content at assembly time. You can only allocate memory for your variables using labels and the `.byte` directive:
The `.byte` Directive:
The `.byte` directive can only be used in data segment (`.dseg`).
This directive cannot be used in the code or eeprom regions because this only allocates memory without assigning specific values to it. Instead, use `.db` or `.dw` for data in the code or eeprom segments.
Internal Assembler Error:
If you get an "internal assembler error" please contact the project maintainer via the GitHub issue tracker: <https://github.com/Ro5bert/avra/issues>. Be sure to include a code example and a description of your working environment.
Originally written by John Anders Haugum; subsequently maintained by Tobias Weber (v0.7+), Burkhard Arenfeld (v1.2), Jerry Jacobs (v1.3) and Virgil Dupras (v1.4). This manual page has been produced by Milan Kupcevic <milan@debian.org> for the Debian project and can be used by others. See AUTHORS for complete list of contributors.
Copyright © 1998-2003, 2004, 2005, 2006, 2007, 2010, 2019, 2020 Jon Anders Haugum, Tobias Weber, Burkhard Arenfeld, Robert Russell, Jerry Jacobs et al. License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>. This is free software; you are free to change and redistribute it under certain conditions. There is NO WARRANTY to the extent permitted by law.
avrdude(1)
March 2023 | avra 1.4.2 |