.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. .TH AVRA "1" "March 2023" "avra 1.4.2" "User Commands" .SH NAME avra \- assembler for the AVR microcontroller family .SH SYNOPSIS .B avra [\fI\,OPTION\/\fR]... \fI\,FILE\/\fR .SH DESCRIPTION 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. .SH OPTIONS .TP \fB\-d\fR, \fB\-\-debugfile\fR debug file name .TP \fB\-D\fR, \fB\-\-define\fR [=] define symbol .TP \fB\-e\fR, \fB\-\-eepfile\fR create EEPROM contents file .TP \fB\-f\fR, \fB\-\-filetype\fR O|M|I|G output file type .TP \fB\-I\fR, \fB\-\-includepath\fR additional include paths (default: \fI\,/usr/share/avra\/\fP) .TP \fB\-l\fR, \fB\-\-listfile\fR create list file .TP \fB\-m\fR, \fB\-\-mapfile\fR create map file .TP \fB\-o\fR, \fB\-\-outfile\fR output file name .TP \fB\-O\fR, \fB\-\-overlap\fR e|w|i issue error/warning/ignore overlapping code .TP \fB\-\-devices\fR list out supported devices .TP \fB\-\-listmac\fR list macro expansion in listfile .TP \fB\-\-max_errors\fR maximum number of errors before exit (default: 10) .TP \fB\-\-version\fR version information .TP \fB\-h\fR, \fB\-\-help\fR general help .TP FILE file to assemble .SH "AVRA USAGE" 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). .SH "WARNING SUPPRESSION" There is a possibility to suppress certain warnings. Currently only register reassignment warnings can be suppressed: .IP avra \fB\-W\fR NoRegDef .SH "USING DIRECTIVES" 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. .PP Directive `.define`: .PP 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: .IP \&.define network 1 .PP Now `network` is set to the value 1. You can also define names without values: .IP \&.define network .PP 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: .IP \&.ifndef network \&.define network 0 \&.endif .PP Directives `.if` and `.else`: .PP 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: .IP \&.if network = 1 \&.include "include\etcpip.asm" \&.else \&.include "include\edummynet.asm" \&.endif .PP There is also an `.elif` ("else if") directive, which does what you think. .PP Directive `.error`: .PP 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: .IP \&.ifndef network \&.error "network is not configured!" ; the assembler stops here .IP \&.endif .PP Directives `.nolist` and `.list`: .PP 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. .PP Directive `.includepath`: .PP 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. .SH "USING INCLUDE FILES" To avoid multiple inclusion of include files, you can use some directives, as shown in the following example: .IP \&.ifndef _MYFILE_ASM_ ; Avoid multiple inclusion of myfile.asm \&.define _MYFILE_ASM_ .IP ; Anything here will only be included once. .IP \&.endif .SH "USING BUILD DATE META TAGS" You can use some special tags that AVRA supports to implement compiler build time and date into your program: .TP %MINUTE% is replaced by the current minute (00\-59) .TP %HOUR% is replaced by the current hour (00\-23) .TP %DAY% is replaced by the current day of month (01\-31) .TP %MONTH% is replaced by the current month (01\-12) .TP %YEAR% is replaced by the current year (2004\-9999) .PP For example, these tags can be used as follows: .IP buildtime: .db "Release date %DAY%.%MONTH%.%YEAR% %HOUR%:%MINUTE%" .PP This line will then be assembled by AVRA into: .IP buildtime: .db "Release date 10.05.2004 19:54" .PP As another example, you can create an automatically\-updating serial number with meta tags: .IP \&.define serialnumber %DAY% + %MONTH%*31 + (%YEAR% \- 2000) *31*12 .PP The `%TAG%` is translated before any other parsing happens. The real output can be found in the list file. .SH "MACRO FEATURES" 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. .PP Automatic Type Conversion For Macros: .PP 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. .PP Macro Data Types: .PP 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: .TP immediate values _i .TP registers _8,_16,_24,_32,_40,_48,_56,_64 .TP void parameter _v .PP See the following section for examples on how these types work. .PP 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. .PP Examples For Automatic Type Conversion and Macro Overloading: .PP To simplify the examples below, we redefine some registers: .TP \&.def a = r16 ; general purpose registers .IP \&.def b = r17 \&.def c = r18 \&.def d = r19 .TP \&.def w = r20 ; working registers .IP \&.def v = r21 .PP If we subtract the 16 bit value `c:d` from `a:b`, we usually have to use the following command sequence: .IP sub b,d sbc a,c .PP Now we can use macros to simplify subtraction with 16 bit values: .IP \&.macro subs .IP \&.message "no parameters specified" .IP \&.endm .IP \&.macro subs_16_16 .IP sub @1,@3 sbc @0,@2 .IP \&.endm .IP \&.macro subs_16_8 .TP sub @1,@2 .IP sbci @0,0 .IP \&.endm .IP ; Now we can write a 16 bit minus 16 bit subtraction as: .IP subs [a:b,c:d] .IP ; Or, for a 16 bit minus 8 bit subtraction: .IP subs [a:b,c] .PP 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. .IP \&.macro load .IP ; This message is shown if you use the macro within your code ; specifying no parameters. If your macro allows the case where ; no parameters are given, exchange .message with your code. \&.message "no parameters specified" .IP \&.endm .IP ; Here we define the macro "load" for the case it is being used ; with two registers as first parameter and an immediate (constant) ; value as second parameter: .IP \&.macro load_16_i .IP ldi @0,high(@2) ldi @1,low(@2) .IP \&.endm .IP ; The same case, but now with a 32 bit register value as first ; parameter: .IP \&.macro load_32_i .IP ldi @0,BYTE4(@4) ldi @1,BYTE3(@4) ldi @2,high(@4) ldi @3,low(@4) .IP \&.endm .IP ; Now these macros can be invoked as follows: .TP load [a:b,15] ; Uses macro load_16_i to load immediate. .IP load [a:b:c:d,15] ; Uses macro load_32_i to load immediate. .PP More Examples: .IP \&.dseg counter: .byte 2 .IP \&.cseg .TP \&.macro poke .IP \&.message "no parameters" \&.endm .TP \&.macro poke_i_16_i .TP ldi @1,high(@3) .TP sts @0+0,@1 .TP ldi @2,low(@3) .TP sts @0+1,@2 .IP \&.endm .TP \&.macro poke_i_i .TP ldi w,@1 .TP sts @0+0,w .IP \&.endm .TP \&.macro poke_i_v_i .TP ldi w,high(@3) .TP sts @0+0,w .TP ldi w,low(@3) .TP sts @0+1,w .IP \&.endm .TP \&.macro poke_i_v_v_v_i .TP ldi w,high(@3) .TP sts @0+0,w .TP ldi w,low(@3) .TP sts @0+1,w .TP ldi w,BYTE3(@3) .TP sts @0+2,w .TP ldi w,BYTE4(@3) .TP sts @0+3,w .IP \&.endm .IP ; This writes 9999 into the memory at 'counter' using only the working .IP ; register for transferring the values. .IP poke [counter,w:w,9999] .IP ; This works the same as above, but the transferred value 9999 is also ; kept in the pair of registers a:b. .IP poke [counter,a:b,9999] .IP ; In this design 'w' is always a working register, which implies that ; it cannot be used for normal variables. The following example ; uses poke_i_i because the parameter contains two immediate values. .IP poke [counter,9999] ;uses poke_i_i .IP ; To be able to choose between a 8, 16, or 32 bit operation, you just ; add a void parameter. .IP poke [counter,,9999] ;uses poke_i_v_i .IP ; And the same for 32 bit pokes: .IP poke [counter,,,,9999] ;uses poke_i_v_v_v_i .PP Loops Within Macros: .PP 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. .PP Loop Example: .IP ; Definition of the macro .IP \&.macro write_8_8 write_%: .TP st Z+,@0 .TP dec @1 .IP brne write_% .IP \&.endm .IP ; Use in user code .IP write [a,b] write [c,d] .IP ; After assembling this code, the result looks like this: .IP write_1: .TP st Z+,a .TP dec b .IP brne write_1 .IP write_2: .TP st Z+,c .TP dec d .IP brne write_2 .SH "WARNINGS AND ERRORS" Here are some frequently asked questions about common errors. .PP Constant Out of Range: .PP This warning occurs if a value exceeds the byte or word value of a assignment. Read the comment posted by Jim Galbraith: .PP The expression (~0x80) is a Bitwise Not operation. This operator returns the input expression with all its bits inverted. If 0x80 represents \fB\-128\fR, 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. .PP Can't Use `.DB` Directive in Data Segment: .PP 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: .IP \&.dseg my_string: .byte 15 .PP The `.byte` Directive: .PP The `.byte` directive can only be used in data segment (`.dseg`). .PP 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. .PP Internal Assembler Error: .PP If you get an "internal assembler error" please contact the project maintainer via the GitHub issue tracker: . Be sure to include a code example and a description of your working environment. .SH AUTHOR 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 for the Debian project and can be used by others. See AUTHORS for complete list of contributors. .SH COPYRIGHT Copyright \(co 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 . 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. .SH "SEE ALSO" avrdude(1)