Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6400 punk_joker 1
README
2
======
3
 
4
General and licensing information
5
---------------------------------
6
AVRA v1.3.0 - Assember for the Atmel AVR microcontroller family
7
 
8
Licensing information
9
~~~~~~~~~~~~~~~~~~~~~
10
 
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version. Please read below for for information.
15
 
16
Disclaimer
17
~~~~~~~~~~
18
 
19
This program is distributed in the hope that it will be useful, but
20
WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
GNU General Public License for more details.
23
 
24
GNU General Public License
25
~~~~~~~~~~~~~~~~~~~~~~~~~~
26
 
27
You should have received a copy of the GNU General Public License
28
along with this program; see the file "COPYING".  If not, visit
29
http://www.gnu.org or write to the Free Software Foundation, Inc.,
30
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. You can
31
also contact the authors of AVRA to receive a copy of the COPYING file.
32
 
33
Trademarks and copyright
34
~~~~~~~~~~~~~~~~~~~~~~~~
35
 
36
Atmel, AVR, AVR Studio, Intel, Windows are registered enterprises, brands
37
and registered trademarks. The mentioned companies have no relation to
38
AVRA and are therefore not responslible for any problems that occur when
39
using AVRA. Many thanks for your products, support and efforts.
40
 
41
 
42
Introducion
43
-----------
44
 
45
AVRA is an assembler for Atmel AVR microcontrollers, and it is almost
46
compatible with Atmel's own assembler AVRASM32. The programming
47
principles and conceptions are based on the ANSI programming language "C".
48
 
49
The initial version of AVRA was written by John Anders Haugum. He released
50
all versions until v0.7. All later versions were released by Tobias Weber.
51
 
52
 
53
Differences between AVRA and AVRASM32
54
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
 
56
There are some differences between the original Atmel assembler AVRASM32 and AVRA. Basically AVRA is designed to replace AVRASM32 without special changes in your current Atmel AVR Studio enviroment.
57
Command line options have been adapted as far as it was possible until now. Jumping to fault containing line directly by double-clicking on the error message in the output window does work as with AVRASM32.
58
 
59
The differences in detail
60
~~~~~~~~~~~~~~~~~~~~~~~~~
61
 
62
    - Support for some extra preprocessor directives.
63
 
64
      .define, .undef, .ifdef, .ifndef, .if, .else, .endif, .elif, .elseif, .warning
65
 
66
    - Not all command line options are supported.
67
      Specifying an eeprom file (-e) is not supported. All eeprom data is
68
      put out into a file called program.eep.hex and always Intel hex
69
      format. Other hex file formats than Intel are currently not supported.
70
 
71
    - Forward references not supported for .ifdef and .ifndef directives.
72
      This makes sure, that directives like .ifdef and .undef are working
73
      properly. If you are familiar with the C programming language, you
74
      should get easily into AVRA. See chapter "Programming techniques" for
75
      more information about how to write proper code.
76
 
77
    - Enhanced macro support
78
      AVRA has some new features for writing flexible macros. This should
79
      increase the ability to reuse code e.g. build your own library.
80
 
81
    - Debugging support
82
      AVRA creates a coff file everytime the assembly was sucessful. This
83
      file allows AVR Studio or any coff compatible debugger to simulate
84
      or emulate the program.
85
 
86
    - Meta tags for assembly time
87
      This helps you tracking versions of your software and can also be
88
      used to generate customer specific serial numbers.
89
 
90
 
91
Compatibility
92
~~~~~~~~~~~~~
93
 
94
Since AVRA is written in ANSI C, it should be possible to compile it on
95
most system platforms. If you have problems compiling AVRA, please leave
96
a message on the sourceforge message board or send a mail to the
97
authors of AVRA.
98
 
99
 
100
Installation
101
------------
102
 
103
To install avra you should copy the avra-executable to an apropriate
104
location. To compile you should rename the appropriate makefile, and
105
perform a make (use smake for Amiga SAS/C, and nmake for Mickeysoft
106
visual c++).
107
 
108
 
109
Linux
110
~~~~~
111
 
112
To compile avra you need gcc and the automake utilities. These will create
113
a ./configure script that evaluates your system enviroment. To get the
114
AVRA executable, you have to issue the following commands:
115
 
116
aclocal
117
autoconf
118
automake -a
119
./configure
120
make && make install
121
 
122
AmigaOS
123
~~~~~~~
124
 
125
avra can be copied any apropriate directory. If you are using the source
126
distribution a 'make install' will do the same.
127
 
128
 
129
Microsoft Windows
130
~~~~~~~~~~~~~~~~~
131
 
132
If you received the Windows binary package, look into the \bin
133
directory where you can find avra.exe. This should be copied to any
134
apropriate location. You can also overwrite AVRASM32.EXE in your
135
Atmel AVR Studio. If you want to compile it yourself you could download then
136
OpenWatcom C/C++ Toolchain for windows and create a new project and add the C
137
and H files to it and compile.
138
 
139
Apple OS X
140
~~~~~~~~~~
141
 
142
If you recieved the Apple OS X binary package, look into the bin directory this
143
file is compiled universal and should run on intel 32 and 64 bit and powerpc. If
144
you want to compile it yourself go to the src directory and invoke `make -f
145
makefiles/Makefiles.osx` and then the executable should be created.
146
 
147
 
148
Synopsis
149
--------
150
 
151
Command line usage
152
~~~~~~~~~~~~~~~~~~
153
 
154
    usage: AVRA [-f][O|M|I|G] output file type
155
             [-o ] output file name
156
             [-l ] generate list file
157
             [-m ] generate map file
158
             [--define [=]]  [--includedir ] [--listmac]
159
             [--max_errors ] [--devices] [--version]
160
             [-h] [--help] general help
161
             [-W NoRegDef] supress register redefinition warnings
162
             
163
 
164
 
165
Parameter list
166
~~~~~~~~~~~~~~
167
 
168
    --listfile    -l : Create list file
169
    --mapfile     -m : Create map file
170
    --define      -D : Define symbol.
171
    --includedir  -I : Additional include dirs.
172
    --listmac        : List macro expansion in listfile.
173
    --max_errors     : Maximum number of errors before exit
174
                       (default: 10)
175
    --devices        : List out supported devices.
176
    --version        : Version information.
177
    --help, -h       : This help text.
178
 
179
 
180
Warning supression
181
~~~~~~~~~~~~~~~~~~
182
 
183
Since avra 1.1 there is a possibility to supress certain warnings.
184
Currently only register reassignment warnings can be supressed.
185
 
186
Example: avra -W NoRegDef
187
 
188
 
189
Programming techniques
190
----------------------
191
 
192
 
193
Using directives
194
~~~~~~~~~~~~~~~~
195
 
196
AVRA offers a number of directives that are not part of Atmel's
197
assembler. These directives should help you creating versatile code that
198
can be designed more modular.
199
 
200
Directive .define
201
^^^^^^^^^^^^^^^^^
202
 
203
To define a constant, use ".define". This does the same thing as ".equ",
204
it is just a little more C style. Keep in mind that AVRA is not case
205
sensitive. Do not mix ".def" and ".define", because ".def" is used to
206
assign registers only. This is due to backward compatibility to Atmel's
207
AVRASM32. Here is an example on how .define can be used.
208
 
209
    .define network 1
210
 
211
Now "network" is set to the value 1. You may want to assemble a specific
212
part of your code depeding on a define or switch setting. You can test
213
your defined word on existence (.ifdef and .ifndef) as well as on the
214
value it represents. The following code shows a way to prevent error
215
messages due to testing undefined constants. Conditional directives must
216
always end with an .endif directive.
217
 
218
    .ifndef network
219
    .define network 0
220
    .endif
221
 
222
Directive .if and .else
223
^^^^^^^^^^^^^^^^^^^^^^^
224
 
225
The three lines in the last example set the default value of "network".
226
In the next example, you see how we can use default values. If a constant
227
has not defined previously, it is set to zero. Now you can test wether
228
e.g. network support is included into the assemby process.
229
 
230
    .if network = 1
231
    .include "include\tcpip.asm"
232
    .else
233
    .include "include\dummynet.asm"
234
    .endif
235
 
236
In the second part of the above listing you see the use of .else, which
237
defines the part of the condition that is being executed if the equation
238
of the preceding .if statement is not equal. You can also use the else
239
statement to test another equasion. For that purpose use .elif, which
240
means "else if". Always close this conditional part with ".endif"
241
 
242
Directive .error
243
^^^^^^^^^^^^^^^^
244
 
245
This directive can be used to throw errors if a part in the code has reached
246
that should not be reached. The following example shows how we can stop
247
the assembly process if a particular value has not been previously set.
248
 
249
    .ifndef network
250
    .error "network is not configured!" ;the assembler stops here
251
 
252
Directive .nolist and .list
253
^^^^^^^^^^^^^^^^^^^^^^^^^^^
254
 
255
The ouput to the list file can be paused by this two directives. After
256
avra discovers a .nolist while assembling, it stops output to the list file.
257
After a .list directive is detected, it continues the normal list file output.
258
 
259
Directive .includepath
260
^^^^^^^^^^^^^^^^^^^^^^
261
 
262
By default, any file that is included from within the source file must
263
either be a single filename or a complete absolute path. With the directive
264
.includepath you can set an additional include path . Furthermore you can
265
set as many include paths as you want. Be sure not no use same filename
266
in separate includes, because then it is no longer clear which one avra
267
should take.
268
 
269
Using include files
270
-------------------
271
 
272
To avoid multiple inclusions of include files, you may use some pre-
273
processor directives. See example file stack.asm that is being included
274
into the main programm file as well as in other include files.
275
 
276
    .ifndef _STACK_ASM_
277
    .define _STACK_ASM_
278
 
279
    .include "include/config.inc"
280
 
281
    ; *** stack macro ***
282
 
283
    .dseg
284
    m_stack:    .byte __stack_size__
285
    .cseg
286
 
287
    .macro      stack_setup
288
        load    [v:w,m_stack + __stack_size__]
289
	outp    [SPREG,v:w]
290
    .endm
291
 
292
    .endif ; avoid multiple inclusion of stack.asm
293
 
294
 
295
Using build date meta tags
296
~~~~~~~~~~~~~~~~~~~~~~~~~~
297
 
298
If you like to implement compiler build time and date into your
299
program, you can make use of some sepcial tags that avra supports.
300
 
301
    %MINUTE%  is being replaced by the current minute (00-59)
302
    %HOUR%    is being replaced by the current hour (00-23)
303
    %DAY%     is being replaced by the current day of month (01-31)
304
    %MONTH%   is being replaced by the current month (01-12)
305
    %YEAR%    is being replaced by the current year (2004-9999)
306
 
307
    buildtime: .db "Release date %DAY%.%MONTH%.%YEAR% %HOUR%:%MINUTE%"
308
 
309
This line will then assembled by avra into:
310
 
311
    buildtime: .db "Release date 10.05.2004 19:54"
312
 
313
You may also create a self defined serial number with meta tags:
314
 
315
    .define serialnumber %DAY% + %MONTH%*31 + (%YEAR% - 2000) *31*12
316
 
317
The %TAG% is translated before any other parsing happens. The real
318
output can be found in the list file.
319
 
320
Macro features
321
--------------
322
 
323
Sometimes you have to work with 16 bit or greater variables stored
324
in 8 bit registers. The enhanced macro support allows you to write short
325
and flexible macros that simplify access to big variables. The extended
326
mode is active, as soon as you use parenthesis like this "[ ]" to wrap
327
macro parameters.
328
 
329
Auto type conversion for macros
330
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
331
 
332
Values representing more than 8 Bits are usualy kept in a set of byte
333
wide registers. To simplify 16 Bit or greater operations, I added a new
334
language definitions. Words can be written as r16:r17, whereas register
335
r16 contains the higher part and register r17 the lower part of this
336
16 Bit value.
337
 
338
Macro data types
339
^^^^^^^^^^^^^^^^
340
 
341
There are 3 data types that can be used. They will be added as character
342
separated by one underline character.
343
 
344
    immediate values  _i
345
    registers         _8,_16,_24,_32,_40,_48,_56,_64
346
    void parameter    _v
347
 
348
16 Bit Source and Destionation registers 'dst' and 'src'
349
 
350
        src = YH:YL
351
        dst = ZH:ZL
352
 
353
Within the parenthesis, the two words src and dst are interpreted as YH:YL
354
and ZH:ZL. Normal code outside of the macro parameter parenthesis can
355
still make use of these special key words "src" and "dst".
356
 
357
Examples for automatic type conversion
358
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
359
 
360
To simplify the parameters in the demonstration below, we need to
361
redefine some registers.
362
 
363
        .def    a = r16   ; general purpose registers
364
        .def    b = r17
365
        .def    c = r18
366
        .def    d = r19
367
 
368
        .def    w = r20   ; working register
369
        .def    v = r21   ; working register
370
 
371
If we substract 16 Bit values stored in a, higher byte and b, lower byte
372
with that in c:d, we usually have to use the following command sequence:
373
 
374
	sub     b,d
375
	sbc     a,c
376
 
377
Now we can do the following steps to simplify 16 or more Bit manipulations
378
 
379
        .macro  subs
380
        .message "no parameters specified"
381
        .endm
382
 
383
        .macro  subs_16_16
384
        sub     @1,@3
385
        sbc     @0,@2
386
	.endm
387
 
388
        .macro  subs_16_8
389
	sub     @1,@2
390
	sbci    @0,0
391
	.endm
392
 
393
        ;now we can write a 16 Bit subraction as:
394
 
395
        subs    [a:b,c:d]
396
 
397
        ;or for calculating 16 minus 8 Bit
398
 
399
        subs    [a:b,c]
400
 
401
 
402
Overloading macros
403
~~~~~~~~~~~~~~~~~~
404
 
405
Like in you are used to C functions, you can write macros for different
406
parameter lists. If you would like to have a versatile macro, you can
407
specify a unique macro for each parameter situation. See the next sample.
408
 
409
        .macro  load
410
 
411
	; this message is shown if you use the macro within your code
412
	; specifying no parameters. If your macro allows the case where
413
	; no parameters are given, exchange .message with your code.
414
 
415
	.message "no parameters specified"
416
        .endm
417
 
418
        ; Here we define the macro "load" for the case it is being used
419
	; with two registers as first parameter and a immediate (constant)
420
	; value as second parameter.
421
 
422
        .macro  load_16_i
423
        ldi     @0,high(@2)
424
        ldi     @1,low(@2)
425
        .endm
426
 
427
        ; the same case, but now with a 32 bit register value as first
428
	; parameter
429
 
430
        .macro  load_32_i
431
        ldi     @0,BYTE4(@4)
432
        ldi     @1,BYTE3(@4)
433
        ldi     @2,high(@4)
434
        ldi     @3,low(@4)
435
        .endm
436
 
437
        ; Now let's see how these macros are being used in the code
438
 
439
	load 	[a:b,15]     ;uses macro load_16_i to load immediate
440
 
441
	load	[a:b:c:d,15] ;uses macro load_32_i to load immediate
442
 
443
 
444
More examples
445
~~~~~~~~~~~~~
446
 
447
       .dseg
448
       counter  .byte 2
449
       .cseg
450
 
451
       .macro   poke
452
       .message "no parameters"
453
       .endm
454
 
455
       .macro   poke_i_16_i
456
       ldi      @1,high(@3)
457
       sts      @0+0,@1
458
       ldi      @2,low(@3)
459
       sts      @0+1,@2
460
       .endm
461
 
462
       .macro   poke_i_i
463
       ldi      w,@1
464
       sts      @0+0,w
465
       .endm
466
 
467
       .macro   poke_i_v_i
468
       ldi      w,high(@3)
469
       sts      @0+0,w
470
       ldi      w,low(@3)
471
       sts      @0+1,w
472
       .endm
473
 
474
       .macro   poke_i_v_v_v_i
475
       ldi      w,high(@3)
476
       sts      @0+0,w
477
       ldi      w,low(@3)
478
       sts      @0+1,w
479
       ldi      w,BYTE3(@3)
480
       sts      @0+2,w
481
       ldi      w,BYTE4(@3)
482
       sts      @0+3,w
483
       .endm
484
 
485
 
486
       ; this writes '9999' into the memory at 'counter'
487
       ; uses only the working register for transfering the values.
488
 
489
       poke     [counter,w:w,9999]
490
 
491
       ; works same as above, but the transferred value '9999' is also
492
       ; kept in the pair of register a:b
493
 
494
       poke     [counter,a:b,9999]
495
 
496
       ; in my design 'w' is always working reg. which implies that
497
       ; it cannot be used for normal variables. The following example
498
       ; uses poke_i_i because the parameter contains two immediate values.
499
 
500
       poke     [counter,9999] ;uses poke_i_i
501
 
502
       ; to be able to choose between a 8,16 or 32 Bit operation, you just
503
       ; add a void parameter.
504
 
505
       poke     [counter,,9999] ;uses poke_i_v_i
506
 
507
       ; and the same for 32 Bit pokes
508
 
509
       poke     [counter,,,,9999] ;uses poke_i_v_v_v_i
510
 
511
Loops within macros
512
~~~~~~~~~~~~~~~~~~~
513
 
514
One problem you may have experienced, is that labels defined within macros
515
are defined twice if you call the macro for example two times. Now you can
516
use labels for macro loops. Loops within macros must end with '_%'. the
517
"%" symbol is replaced by a running number.
518
 
519
Loop example
520
^^^^^^^^^^^^
521
 
522
       ; Definition of the macro
523
 
524
       .macro   write_8_8
525
       write_%:
526
            st      Z+,@0
527
            dec     @1
528
            brne    write_%
529
       .endm
530
 
531
       ; Use in user code
532
 
533
       write   [a,b]
534
       write   [c,d]
535
 
536
       ; After assembling this code, the result looks like this
537
 
538
       write_1:
539
            st          Z+,a
540
            dec         b
541
            brne        write_1
542
       write_2:
543
            st          Z+,c
544
            dec         d
545
            brne        write_2
546
 
547
Warnings and Errors
548
-------------------
549
 
550
Some errors and warnings may confuse you a little bit so we will try to
551
clear some frequently asked questions about such cases.
552
 
553
Constant out of range
554
~~~~~~~~~~~~~~~~~~~~~
555
 
556
This warning occurs if a value exceeds the byte or word value of a assignment.
557
Read the comment posted by Jim Galbraith:
558
 
559
The expression (~0x80) is a Bitwise Not operation.  This
560
operator returns the input expression with all its bits
561
inverted.  If 0x80 represents -128, then 0x7f, or +127
562
should be ok.  If this is considered as a 32-bit expression
563
(AVRA internal representation), then it appears to be more
564
like oxffffffff-0x80 or 0xffffffff^0x80.  The result would then
565
be 0xffffff7f.  The assembler would then have to be told or it
566
would have to decide, based on context, how much
567
significance to assign to the higher bits.  I have also
568
encountered such conditions with various assemblers,
569
including AVRA.  To make sure the assembler does what I
570
really want, I use a construct like 0xff-0x80 or 0xff^0x80.
571
This way the bit significance cannot extend beyond bit-7 and
572
there cannot be any misunderstanding.
573
 
574
Can't use .DB directive in data segment
575
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
576
 
577
.DB and .DW is only used to assign constant data in eeprom or code space.
578
The reason why using it within data segment is forbidden is, that you
579
cannot set ram content at assembly time. The values must be programmed into
580
ROM area and at boot read from ROM into RAM. This is up to the user code.
581
You can only allocate memory for your variables using labels and the .byte
582
directive.
583
 
584
    .dseg
585
    my_string: .byte 15
586
 
587
BYTE directive
588
~~~~~~~~~~~~~~
589
 
590
.BYTE directive can only be used in data segment (.DSEG)
591
 
592
This directive cannot be used in code or eeprom region because this only
593
allocates memory without assgning distinct values to it. Please use .db
594
or .dw instead.
595
 
596
Internal assembler error
597
~~~~~~~~~~~~~~~~~~~~~~~~
598
 
599
If you get an "Internal assembler error" please contact the project maintainer
600
by sending him a code example and a description of your working enviroment.
601
 
602
 
603
AVRA internals
604
--------------
605
 
606
This section provides thoughts of the avra internal design. I have to admit
607
that the code of avra is anything else than clean and optimized. To increase
608
the code readability I will try to give you some standards that should improve
609
quality. The following standards are similar to what GNU proposes.
610
 
611
Coding standards
612
~~~~~~~~~~~~~~~~
613
 
614
Tab space is always 2 spaces. The Tab character (ascii 9) is not used.
615
if,while,for are always opened on the same line but closed on the next line.
616
The closing bracket is in the same column as the first letter of the loop
617
directive.
618
 
619
    Example:
620
----
621
    while(i > 0) {
622
     do_something();
623
    }
624
----
625
 
626
 
627
Credits
628
-------
629
 
630
We would like to thank the following people for giving contributions,
631
patches and bug reports, as well as suggestions and new ideas.
632
 
633
----
634
      Jon Anders Haugum (project founder)
635
      Burkhard Arenfeld (release 1.2.0)
636
      Tobias Weber (old maintainer)
637
      Jerry Jacobs (release 1.3.0)
638
      Bernt Hembre
639
      Nils Strøm
640
      Roberto Biancardi
641
      Qwerty Jones
642
      Ben Hitchcock (Maker of the mac port)
643
      Daniel Drotos
644
      Laurence Boyd II
645
      Varuzhan Danielyan
646
      Laurence Turner
647
      Eugene R. O'Bryan
648
      Dmitry Dicky
649
      Bob Harris (Maker of coff support)
650
      Tobias Weber (enhanced macro support)
651
      Lesha Bogdanow
652
      Jim Galbraith
653
      Mark Brinicombe
654
      Igor Nikolayenko
655
      Peter Hettkamp
656
      Herb Poppe
657
      David Burke
658
      Alexey Pavluchenko
659
      Alan Probandt
660
      Mariusz Matuszek
661
      Arne Rossius
662
      Marti Tichacek
663
      Patrick Parity
664
      Johannes Overmann
665
      Roland Riegel
666
      Peter Katzmann
667
      Donald D. Davis
668
----
669
 
670
And all the anonymous people who submitted patches!
671
 
672
Thank you for your work and support.
673
 
674
References
675
----------
676
 
677
    http://www.suprafluid.com/avra
678
    http://www.avrfreaks.de
679
    http://www.atmel.com