[go: up one dir, main page]

File: README

package info (click to toggle)
avra 1.0.1-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 532 kB
  • ctags: 927
  • sloc: ansic: 5,934; asm: 737; pascal: 624; makefile: 85
file content (662 lines) | stat: -rwxr-xr-x 21,731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
*****************************************************************************
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*****************************************************************************

    AVRA V 1.0.1 - Assember for the Atmel AVR microcontroller family
       Copyright (C) 1998-2004 Jon Anders Haugum, Tobias Weber

*****************************************************************************
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*****************************************************************************


Table of contents

1. General and licensing information
   1.1 Licensing information
   1.2 Disclaimer
   1.3 GNU General Public License
   1.4 Trademarks and copyright

2. Introducion
   2.1 Differences between AVRA and AVRASM23
   2.1.1 The differences in detail
   2.2 Compatibility

3. Installation
   3.1 Linux
   3.2 AmigaOS
   3.3 Win32 (Windows 95, 98, 2000, NT and XP)
   3.4 Dev-C++ enviroment

4. Synopsis
   4.1 Command line usage
   4.2 Parameter list

5. Programming techniques
   5.1 Using directives
   5.1.1 Directive .define
   5.1.2 Directive .if and .else
   5.1.3 Directive .error
   5.2 Using include files
   5.3 Using build date meta tags

6. Macro features
   6.1 Auto type conversion for macros
   6.1.1 Macro data types
   6.1.2 Examples for automatic type conversion
   6.2 Overloading macros
   6.2.1 More expamples
   6.3 Loops within macros
   6.3.1 Loop example

7. Warnings and Errors
   7.1 Constant out of range
   7.2 Can't use .DB directive in data segment
   7.3 Internal assembler error

8. Credits

9. Internet sites and links


 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 


1. General and licensing information

1.1 Licensing information

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version. Please read below for for information.


1.2 Disclaimer

    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.


1.3 GNU General Public License
    
    You should have received a copy of the GNU General Public License
    along with this program; see the file "COPYING".  If not, visit
    http://www.gnu.org or write to the Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. You can
    also contact the authors of AVRA to receive a copy of the COPYING file.


1.4 Trademarks and copyright

    Atmel, AVR, AVR Studio, Intel, Windows are registered enterprises, brands
    and registered trademarks. The mentioned companies have no relation to
    AVRA and are therefore not responslible for any problems that occur when
    using AVRA. Many thanks for your products, support and efforts.

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 


2. Introducion

    AVRA is an assembler for Atmel AVR microcontrollers, and it is almost
    compatible with Atmel's own assembler AVRASM32. The programming
    principles and conceptions are based on the ANSI programming language "C".

    The initial version of AVRA was written by John Anders Haugum. He released
    all versions until v0.7. All later versions were released by Tobias Weber.

    
2.1 Differences between AVRA and AVRASM32

    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. 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.


2.1.1 The differences in detail

    - Support for some extra preprocessor directives.

      .define, .undef, .ifdef, .ifndef, .if, .else, .endif, .elif, .warning

    - Not all command line options are supported. 
      Specifying an eeprom file (-e) is not supported. All eeprom data is
      put out into a file called program.eep.hex and always Intel hex
      format. Other hex file formats than Intel are currently not supported.

    - Forward references are not supported.
      Like in C, you have to define everything before you are using it,
      excepting labels. This makes sure, that directives like .ifdef and
      .undef are working properly. If you are familiar with the C programming
      language, you should get easily into AVRA. See chapter "Programming
      techniques" for more information about how to write proper code.

    - Enhanced macro support
      AVRA has some new features for writing flexible macros. This should
      increase the ability to reuse code e.g. build your own library.

    - Debugging support
      AVRA creates a coff file everytime the assembly was sucessful. This
      file allows AVR Studio or any coff compatible debugger to simulate
      or emulate the program.

    - Meta tags for assembly time
      This helps you tracking versions of your software and can also be
      used to generate customer specific serial numbers.


2.2 Compatibility

    Since AVRA is written in ANSI C, it should be possible to compile it on
    most system platforms. If you have problems compiling AVRA, please leave
    a message on the sourceforge message board or send a mail to the
    authors of AVRA.

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 


3. Installation

    To install avra you should copy the avra-executable to an apropriate
    location. To compile you should rename the appropriate makefile, and
    perform a make (use smake for Amiga SAS/C, and nmake for Mickeysoft
    visual c++).


3.1 Linux

    The default Makefile is created for Linux gcc. You can compile the source
    by typing "make" in the "source" folder. AVRA should be copied to
    /usr/local/bin/ or another apropriate directory. Doing a 'make install'
    will do the same thing.


3.2 AmigaOS

    avra can be copied any apropriate directory. If you are using the source
    distribution a 'make install' will do the same.


3.3 Win32 (Windows 95, 98, 2000, NT and XP)

    If you received the Windows binary package, look into the \bin
    directory where you can find avra.exe. This should be copied to any
    apropriate location. You can also overwrite AVRASM32.EXE in your
    Atmel AVR Studio. A 'nmake install' will copy it and avra.def to c:\bin\


3.4 Dev-C++ enviroment

    Dev-C++ is a GNU development enviroment available for MS Windows.
    This version of AVRA has been mostly developed using this open development
    platform. This nice software is available at http://www.bloodshed.net/

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

4. Synopsis

4.1 Command line usage

   usage: AVRA [-f][O|M|I|G] output file type
            [-o <filename>] output file name
            [-l <filename>] generate list file
            [-m <mapfile>] generate map file
            [--define <symbol>[=<value>]]  [--includedir <dir>] [--listmac]
            [--max_errors <number>] [--devices] [--version]
            [-h] [--help] general help
            <file to assemble>

4.2 Parameter list

   --listfile    -l : Create list file
   --mapfile     -m : Create map file
   --define      -D : Define symbol.
   --includedir  -I : Additional include dirs.
   --listmac        : List macro expansion in listfile.
   --max_errors     : Maximum number of errors before exit
                      (default: 10)
   --devices        : List out supported devices.
   --version        : Version information.
   --help, -h       : This help text.

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 


5. Programming techniques

5.1 Using directives

    AVRA offers a number of directives that are not part of Atmel's
    assembler. These directives should help you creating versatile code that
    can be designed more modular.


5.1.1 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. Do not mix ".def" and ".define", because ".def" is used to
    assign registers only. This is due to backward compatibility to Atmel's
    AVRASM32. Here is an example on how .define can be used.

    .define network 1

    Now "network" is set to the value 1. You may want to assemble a specific
    part of your code depeding 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. Conditional directives must
    always end with an .endif directive.

    .ifndef network
    .define network 0
    .endif


5.1.2 Directive .if and .else

    The three lines in the last example set the default value of "network".
    In the next example, you see how we can use default values. If a constant
    has not defined previously, it is set to zero. Now you can test wether
    e.g. network support is included into the assemby process.

    .if network = 1
    .include "include\tcpip.asm"
    .else
    .include "include\dummynet.asm"
    .endif

    In the second part of the above listing you see the use of .else, which
    defines the part of the condition that is being executed if the equation
    of the preceding .if statement is not equal. You can also use the else
    statement to test another equasion. For that purpose use .elif, which
    means "else if". Always close this conditional part with ".endif"

5.1.3 Directive .error

    This directive can be used to throw errors if a part in the code has reached
    that should not be reached. The following example shows how we can stop
    the assembly process if a particular value has not been previously set.

    .ifndef network
    .error "network is not configured!" ;the assembler stops here


5.2 Using include files

    To avoid multiple inclusions of include files, you may use some pre-
    processor directives. See example file stack.asm that is being included
    into the main programm file as well as in other include files.

    .ifndef _STACK_ASM_
    .define _STACK_ASM_
  
    .include "include/config.inc"

    ; *** stack macro ***
    
    .dseg
    m_stack:    .byte __stack_size__
    .cseg

    .macro      stack_setup
        load    [v:w,m_stack + __stack_size__]
	outp    [SPREG,v:w]
    .endm

    .endif ; avoid multiple inclusion of stack.asm


5.3 Using build date meta tags

    If you like to implement compiler build time and date into your
    program, you can make use of some sepcial tags that avra supports.
    
    %MINUTE%  is being replaced by the current minute (0-59)
    %HOUR%    is being replaced by the current hour (0-23)
    %DAY%     is being replaced by the current day of month (1-31)
    %MONTH%   is being replaced by the current month (1-12)
    %YEAR%    is being replaced by the current year (2004-9999)

    buildtime: .db "Release date %DAY%.%MONTH%.%YEAR% %HOUR%:%MINUTE%"
    
    This line will then assembled by avra into:
    
    buildtime: .db "Release date 10.5.2004 19:54"
   
    You may also create a self defined serial number with meta tags:
    
    .define serialnumber %DAY% + %MONTH%*31 + (%YEAR% - 2000) *31*12

    The %TAG% is translated before any other parsing happens. The real
    output can be found in the list file.

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

6 Macro features

    Sometimes you have to work with 16 bit or greater variables stored
    in 8 bit registers. The enhanced macro support allows you to write short
    and flexible macros that simplify access to big variables. The extended
    mode is active, as soon as you use parenthesis like this "[ ]" to wrap
    macro parameters.


6.1 Auto type conversion for macros

    Values representing more than 8 Bits are usualy kept in a set of byte
    wide registers. To simplify 16 Bit or greater operations, I added a new
    language definitions. Words can be written as r16:r17, whereas register
    r16 contains the higher part and register r17 the lower part of this 
    16 Bit value.


6.1.1 Macro data types

    There are 3 data types that can be used. They will be added as character
    separated by one underline character.

	immediate values  _i
	registers         _8,_16,_24,_32,_40,_48,_56,_64
	void parameter    _v

    16 Bit Source and Destionation registers 'dst' and 'src'

        src = YH:YL
        dst = ZH:ZL

    Within the parenthesis, the two words src and dst are interpreted as YH:YL
    and ZH:ZL. Normal code outside of the macro parameter parenthesis can
    still make use of these special key words "src" and "dst".


6.1.2 Examples for automatic type conversion

    To simplify the parameters in the demonstration below, we need to
    redefine some registers.

        .def    a = r16   ; general purpose registers
        .def    b = r17
        .def    c = r18
        .def    d = r19

        .def    w = r20   ; working register
        .def    v = r21   ; working register

    If we substract 16 Bit values stored in a, higher byte and b, lower byte
    with that in c:d, we usually have to use the following command sequence:

	sub     b,d
	sbc     a,c

    Now we can do the following steps to simplify 16 or more Bit manipulations

        .macro  subs
        .message "no parameters specified"
        .endm

        .macro  subs_16_16
        sub     @1,@3
        sbc     @0,@2 
	.endm

        .macro  subs_16_8
	sub     @1,@2
	sbci    @0,0
	.endm

        ;now we can write a 16 Bit subraction as:

        subs    [a:b,c:d]

        ;or for calculating 16 minus 8 Bit

        subs    [a:b,c]


6.2 Overloading macros

    Like in you are used to C functions, you can write macros for different
    parameter lists. If you would like to have a versatile macro, you can
    specify a unique macro for each parameter situation. See the next sample.

        .macro  load

	; 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"
        .endm

        ; Here we define the macro "load" for the case it is being used
	; with two registers as first parameter and a immediate (constant)
	; value as second parameter.

        .macro  load_16_i
        ldi     @0,high(@2)
        ldi     @1,low(@2)
        .endm

        ; the same case, but now with a 32 bit register value as first
	; parameter

        .macro  load_32_i
        ldi     @0,BYTE4(@4)
        ldi     @1,BYTE3(@4)
        ldi     @2,high(@4)
        ldi     @3,low(@4)
        .endm

        ; Now let's see how these macros are being used in the code

	load 	[a:b,15]     ;uses macro load_16_i to load immediate

	load	[a:b:c:d,15] ;uses macro load_32_i to load immediate


6.2.1 More expamples

       .dseg
       counter  .byte 2
       .cseg

       .macro   poke
       .message "no parameters"
       .endm

       .macro   poke_i_16_i
       ldi      @1,high(@3)
       sts      @0+0,@1
       ldi      @2,low(@3)
       sts      @0+1,@2
       .endm

       .macro   poke_i_i
       ldi      w,@1
       sts      @0+0,w
       .endm

       .macro   poke_i_v_i
       ldi      w,high(@3)
       sts      @0+0,w
       ldi      w,low(@3)
       sts      @0+1,w
       .endm

       .macro   poke_i_v_v_v_i
       ldi      w,high(@3)
       sts      @0+0,w
       ldi      w,low(@3)
       sts      @0+1,w
       ldi      w,BYTE3(@3)
       sts      @0+2,w
       ldi      w,BYTE4(@3)
       sts      @0+3,w
       .endm


       ; this writes '9999' into the memory at 'counter'
       ; uses only the working register for transfering the values.

       poke     [counter,w:w,9999]

       ; works same as above, but the transferred value '9999' is also
       ; kept in the pair of register a:b

       poke     [counter,a:b,9999]

       ; in my design 'w' is always working reg. which implies that
       ; it cannot be used for normal variables. The following example
       ; uses poke_i_i because the parameter contains two immediate values.

       poke     [counter,9999] ;uses poke_i_i

       ; to be able to choose between a 8,16 or 32 Bit operation, you just
       ; add a void parameter.

       poke     [counter,,9999] ;uses poke_i_v_i

       ; and the same for 32 Bit pokes

       poke     [counter,,,,9999] ;uses poke_i_v_v_v_i



6.3 Loops within macros

    One problem you may have experienced, is that labels defined within macros
    are defined twice if you call the macro for example two times. Now you can
    use labels for macro loops. Loops within macros must end with '_%'. the
    "%" symbol is replaced by a running number.


6.3.1 Loop example

       ; Definition of the macro

       .macro   write_8_8
       write_%:
            st      Z+,@0
            dec     @1
            brne    write_%
       .endm

       ; Use in user code

       write   [a,b]
       write   [c,d]

       ; After assembling this code, the result looks like this

       write_1:
            st          Z+,a
            dec         b
            brne        write_1
       write_2:
            st          Z+,c
            dec         d
            brne        write_2

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

7. Warnings and Errors

   Some errors and warnings may confuse you a little bit so we will try to
   clear some frequently asked questions about such cases.

7.1 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.   

7.2 Can't use .DB directive in data segment

   .DB and .DW is only used to assign constant data in eeprom or code space.
   The reason why using it within data segment is forbidden is, that you
   cannot set ram content at assembly time. The values must be programmed into
   ROM area and at boot read from ROM into RAM. This is up to the user code.
   You can only allocate memory for your variables using labels and the .byte
   directive.

   .dseg
   my_string: .byte 15

7.3 .BYTE directive can only be used in data segment (.DSEG)

   This directive cannot be used in code or eeprom region because this only 
   allocates memory without assgning distinct values to it. Please use .db
   or .dw instead.

7.4 Internal assembler error

   If you get an "Internal assembler error" please contact the project maintainer
   by sending him a code example and a description of your working enviroment.


 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

8. Credits

    We would like to thank the following people for giving contributions,
    patches and bug reports, as well as suggestions and new ideas.

      Bernt Hembre
      Nils Strm
      Roberto Biancardi
      Qwerty Jones
      Ben Hitchcock (Maker of the mac port)
      Daniel Drotos
      Laurence Boyd II
      Varuzhan Danielyan
      Laurence Turner
      Eugene R. O'Bryan
      Dmitry Dicky
      Bob Harris (Maker of coff support)
      Tobias Weber (enhanced macro support)
      Lesha Bogdanow
      Jim Galbraith
      Mark Brinicombe
      Igor Nikolayenko
      Peter Hettkamp
      Herb Poppe

    Thank you for your work and support.

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 


9. Internet sites and links

    http://www.avrfreaks.com/
    http://www.atmel.com
    http://avra.sourceforge.net

    you can reach the project maintainer via mail: tobiw@tiscali.de

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 


EOF