Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6400 punk_joker 1
2
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
4
5
6
7
8
9
10
15
16
README
17
18
19
20
  
AVRA
21
  
Assember for the Atmel AVR microcontroller family
22
23
24
25
26
  
27
  
28
  
29
  
30
  
31
  
32
33
34
35
36

README

37
38
39

General and licensing information

40
41

AVRA v1.3.0 - Assember for the Atmel AVR microcontroller family

42

Licensing information

43

This program is free software; you can redistribute it and/or modify

44
it under the terms of the GNU General Public License as published by
45
the Free Software Foundation; either version 2 of the License, or
46
(at your option) any later version. Please read below for for information.

47

Disclaimer

48

This program is distributed in the hope that it will be useful, but

49
WITHOUT ANY WARRANTY; without even the implied warranty of
50
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51
GNU General Public License for more details.

52

GNU General Public License

53

You should have received a copy of the GNU General Public License

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

58
59

Atmel, AVR, AVR Studio, Intel, Windows are registered enterprises, brands

60
and registered trademarks. The mentioned companies have no relation to
61
AVRA and are therefore not responslible for any problems that occur when
62
using AVRA. Many thanks for your products, support and efforts.

63
64

Introducion

65
66

AVRA is an assembler for Atmel AVR microcontrollers, and it is almost

67
compatible with Atmel’s own assembler AVRASM32. The programming
68
principles and conceptions are based on the ANSI programming language "C".

69

The initial version of AVRA was written by John Anders Haugum. He released

70
all versions until v0.7. All later versions were released by Tobias Weber.

71

Differences between AVRA and AVRASM32

72

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.

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

74

The differences in detail

75
    76
  • 77

    78
    Support for some extra preprocessor directives.
    79

    80
    81
    82
    .define, .undef, .ifdef, .ifndef, .if, .else, .endif, .elif, .elseif, .warning
    83
    84
    85
  • 86

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

    92
    93
  • 94

    95
    Forward references not supported for .ifdef and .ifndef directives.
    96
          This makes sure, that directives like .ifdef and .undef are working
    97
          properly. If you are familiar with the C programming language, you
    98
          should get easily into AVRA. See chapter "Programming techniques" for
    99
          more information about how to write proper code.
    100

    101
    102
  • 103

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

    108
    109
  • 110

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

    116
    117
  • 118

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

    123
    124
    125

    Compatibility

    126

    Since AVRA is written in ANSI C, it should be possible to compile it on

    127
    most system platforms. If you have problems compiling AVRA, please leave
    128
    a message on the sourceforge message board or send a mail to the
    129
    authors of AVRA.

    130
    131

    Installation

    132
    133

    To install avra you should copy the avra-executable to an apropriate

    134
    location. To compile you should rename the appropriate makefile, and
    135
    perform a make (use smake for Amiga SAS/C, and nmake for Mickeysoft
    136
    visual c++).

    137

    Linux

    138

    To compile avra you need gcc and the automake utilities. These will create

    139
    a ./configure script that evaluates your system enviroment. To get the
    140
    AVRA executable, you have to issue the following commands:

    141

    aclocal

    142
    autoconf
    143
    automake -a
    144
    ./configure
    145
    make && make install

    146

    AmigaOS

    147

    avra can be copied any apropriate directory. If you are using the source

    148
    distribution a make install will do the same.

    149

    Microsoft Windows

    150

    If you received the Windows binary package, look into the \bin

    151
    directory where you can find avra.exe. This should be copied to any
    152
    apropriate location. You can also overwrite AVRASM32.EXE in your
    153
    Atmel AVR Studio. If you want to compile it yourself you could download then
    154
    OpenWatcom C/C++ Toolchain for windows and create a new project and add the C
    155
    and H files to it and compile.

    156

    Apple OS X

    157

    If you recieved the Apple OS X binary package, look into the bin directory this

    158
    file is compiled universal and should run on intel 32 and 64 bit and powerpc. If
    159
    you want to compile it yourself go to the src directory and invoke make -f
    160
    makefiles/Makefiles.osx and then the executable should be created.

    161
    162

    Synopsis

    163
    164

    Command line usage

    165
    166
    167
    usage: AVRA [-f][O|M|I|G] output file type
    168
             [-o <filename>] output file name
    169
             [-l <filename>] generate list file
    170
             [-m <mapfile>] generate map file
    171
             [--define <symbol>[=<value>]]  [--includedir <dir>] [--listmac]
    172
             [--max_errors <number>] [--devices] [--version]
    173
             [-h] [--help] general help
    174
             [-W NoRegDef] supress register redefinition warnings
    175
             <file to assemble>
    176
    177

    Parameter list

    178
    179
    180
    --listfile    -l : Create list file
    181
    --mapfile     -m : Create map file
    182
    --define      -D : Define symbol.
    183
    --includedir  -I : Additional include dirs.
    184
    --listmac        : List macro expansion in listfile.
    185
    --max_errors     : Maximum number of errors before exit
    186
                       (default: 10)
    187
    --devices        : List out supported devices.
    188
    --version        : Version information.
    189
    --help, -h       : This help text.
    190
    191

    Warning supression

    192

    Since avra 1.1 there is a possibility to supress certain warnings.

    193
    Currently only register reassignment warnings can be supressed.

    194

    Example: avra -W NoRegDef

    195
    196

    Programming techniques

    197
    198

    Using directives

    199

    AVRA offers a number of directives that are not part of Atmel’s

    200
    assembler. These directives should help you creating versatile code that
    201
    can be designed more modular.

    202

    Directive .define

    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
    210
    .define network 1
    211
    212

    Now "network" is set to the value 1. You may want to assemble a specific

    213
    part of your code depeding on a define or switch setting. You can test
    214
    your defined word on existence (.ifdef and .ifndef) as well as on the
    215
    value it represents. The following code shows a way to prevent error
    216
    messages due to testing undefined constants. Conditional directives must
    217
    always end with an .endif directive.

    218
    219
    220
    .ifndef network
    221
    .define network 0
    222
    .endif
    223
    224

    Directive .if and .else

    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
    231
    .if network = 1
    232
    .include "include\tcpip.asm"
    233
    .else
    234
    .include "include\dummynet.asm"
    235
    .endif
    236
    237

    In the second part of the above listing you see the use of .else, which

    238
    defines the part of the condition that is being executed if the equation
    239
    of the preceding .if statement is not equal. You can also use the else
    240
    statement to test another equasion. For that purpose use .elif, which
    241
    means "else if". Always close this conditional part with ".endif"

    242

    Directive .error

    243

    This directive can be used to throw errors if a part in the code has reached

    244
    that should not be reached. The following example shows how we can stop
    245
    the assembly process if a particular value has not been previously set.

    246
    247
    248
    .ifndef network
    249
    .error "network is not configured!" ;the assembler stops here
    250
    251

    Directive .nolist and .list

    252

    The ouput to the list file can be paused by this two directives. After

    253
    avra discovers a .nolist while assembling, it stops output to the list file.
    254
    After a .list directive is detected, it continues the normal list file output.

    255

    Directive .includepath

    256

    By default, any file that is included from within the source file must

    257
    either be a single filename or a complete absolute path. With the directive
    258
    .includepath you can set an additional include path . Furthermore you can
    259
    set as many include paths as you want. Be sure not no use same filename
    260
    in separate includes, because then it is no longer clear which one avra
    261
    should take.

    262
    263

    Using include files

    264
    265

    To avoid multiple inclusions of include files, you may use some pre-

    266
    processor directives. See example file stack.asm that is being included
    267
    into the main programm file as well as in other include files.

    268
    269
    270
    .ifndef _STACK_ASM_
    271
    .define _STACK_ASM_
    272
    273
    274
    275
    .include "include/config.inc"
    276
    277
    278
    279
    ; *** stack macro ***
    280
    281
    282
    283
    .dseg
    284
    m_stack:    .byte __stack_size__
    285
    .cseg
    286
    287
    288
    289
    .macro      stack_setup
    290
        load    [v:w,m_stack + __stack_size__]
    291
        outp    [SPREG,v:w]
    292
    .endm
    293
    294
    295
    296
    .endif ; avoid multiple inclusion of stack.asm
    297
    298

    Using build date meta tags

    299

    If you like to implement compiler build time and date into your

    300
    program, you can make use of some sepcial tags that avra supports.

    301
    302
    303
    %MINUTE%  is being replaced by the current minute (00-59)
    304
    %HOUR%    is being replaced by the current hour (00-23)
    305
    %DAY%     is being replaced by the current day of month (01-31)
    306
    %MONTH%   is being replaced by the current month (01-12)
    307
    %YEAR%    is being replaced by the current year (2004-9999)
    308
    309
    310
    311
    buildtime: .db "Release date %DAY%.%MONTH%.%YEAR% %HOUR%:%MINUTE%"
    312
    313

    This line will then assembled by avra into:

    314
    315
    316
    buildtime: .db "Release date 10.05.2004 19:54"
    317
    318

    You may also create a self defined serial number with meta tags:

    319
    320
    321
    .define serialnumber %DAY% + %MONTH%*31 + (%YEAR% - 2000) *31*12
    322
    323

    The %TAG% is translated before any other parsing happens. The real

    324
    output can be found in the list file.

    325
    326

    Macro features

    327
    328

    Sometimes you have to work with 16 bit or greater variables stored

    329
    in 8 bit registers. The enhanced macro support allows you to write short
    330
    and flexible macros that simplify access to big variables. The extended
    331
    mode is active, as soon as you use parenthesis like this "[ ]" to wrap
    332
    macro parameters.

    333

    Auto type conversion for macros

    334

    Values representing more than 8 Bits are usualy kept in a set of byte

    335
    wide registers. To simplify 16 Bit or greater operations, I added a new
    336
    language definitions. Words can be written as r16:r17, whereas register
    337
    r16 contains the higher part and register r17 the lower part of this
    338
    16 Bit value.

    339

    Macro data types

    340

    There are 3 data types that can be used. They will be added as character

    341
    separated by one underline character.

    342
    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
    351
    src = YH:YL
    352
    dst = ZH:ZL
    353
    354

    Within the parenthesis, the two words src and dst are interpreted as YH:YL

    355
    and ZH:ZL. Normal code outside of the macro parameter parenthesis can
    356
    still make use of these special key words "src" and "dst".

    357

    Examples for automatic type conversion

    358

    To simplify the parameters in the demonstration below, we need to

    359
    redefine some registers.

    360
    361
    362
    .def    a = r16   ; general purpose registers
    363
    .def    b = r17
    364
    .def    c = r18
    365
    .def    d = r19
    366
    367
    368
    369
    .def    w = r20   ; working register
    370
    .def    v = r21   ; working register
    371
    372

    If we substract 16 Bit values stored in a, higher byte and b, lower byte

    373
    with that in c:d, we usually have to use the following command sequence:

    374
    375
    376
    sub     b,d
    377
    sbc     a,c
    378
    379

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

    380
    381
    382
    .macro  subs
    383
    .message "no parameters specified"
    384
    .endm
    385
    386
    387
    388
    .macro  subs_16_16
    389
    sub     @1,@3
    390
    sbc     @0,@2
    391
    .endm
    392
    393
    394
    395
    .macro  subs_16_8
    396
    sub     @1,@2
    397
    sbci    @0,0
    398
    .endm
    399
    400
    401
    402
    ;now we can write a 16 Bit subraction as:
    403
    404
    405
    406
    subs    [a:b,c:d]
    407
    408
    409
    410
    ;or for calculating 16 minus 8 Bit
    411
    412
    413
    414
    subs    [a:b,c]
    415
    416

    Overloading macros

    417

    Like in you are used to C functions, you can write macros for different

    418
    parameter lists. If you would like to have a versatile macro, you can
    419
    specify a unique macro for each parameter situation. See the next sample.

    420
    421
    422
    .macro  load
    423
    424
    425
    426
    ; this message is shown if you use the macro within your code
    427
    ; specifying no parameters. If your macro allows the case where
    428
    ; no parameters are given, exchange .message with your code.
    429
    430
    431
    432
    .message "no parameters specified"
    433
    .endm
    434
    435
    436
    437
    ; Here we define the macro "load" for the case it is being used
    438
    ; with two registers as first parameter and a immediate (constant)
    439
    ; value as second parameter.
    440
    441
    442
    443
    .macro  load_16_i
    444
    ldi     @0,high(@2)
    445
    ldi     @1,low(@2)
    446
    .endm
    447
    448
    449
    450
    ; the same case, but now with a 32 bit register value as first
    451
    ; parameter
    452
    453
    454
    455
    .macro  load_32_i
    456
    ldi     @0,BYTE4(@4)
    457
    ldi     @1,BYTE3(@4)
    458
    ldi     @2,high(@4)
    459
    ldi     @3,low(@4)
    460
    .endm
    461
    462
    463
    464
    ; Now let's see how these macros are being used in the code
    465
    466
    467
    468
    load    [a:b,15]     ;uses macro load_16_i to load immediate
    469
    470
    471
    472
    load    [a:b:c:d,15] ;uses macro load_32_i to load immediate
    473
    474

    More examples

    475
    476
    477
    .dseg
    478
    counter  .byte 2
    479
    .cseg
    480
    481
    482
    483
    .macro   poke
    484
    .message "no parameters"
    485
    .endm
    486
    487
    488
    489
    .macro   poke_i_16_i
    490
    ldi      @1,high(@3)
    491
    sts      @0+0,@1
    492
    ldi      @2,low(@3)
    493
    sts      @0+1,@2
    494
    .endm
    495
    496
    497
    498
    .macro   poke_i_i
    499
    ldi      w,@1
    500
    sts      @0+0,w
    501
    .endm
    502
    503
    504
    505
    .macro   poke_i_v_i
    506
    ldi      w,high(@3)
    507
    sts      @0+0,w
    508
    ldi      w,low(@3)
    509
    sts      @0+1,w
    510
    .endm
    511
    512
    513
    514
    .macro   poke_i_v_v_v_i
    515
    ldi      w,high(@3)
    516
    sts      @0+0,w
    517
    ldi      w,low(@3)
    518
    sts      @0+1,w
    519
    ldi      w,BYTE3(@3)
    520
    sts      @0+2,w
    521
    ldi      w,BYTE4(@3)
    522
    sts      @0+3,w
    523
    .endm
    524
    525
    526
    527
    ; this writes '9999' into the memory at 'counter'
    528
    ; uses only the working register for transfering the values.
    529
    530
    531
    532
    poke     [counter,w:w,9999]
    533
    534
    535
    536
    ; works same as above, but the transferred value '9999' is also
    537
    ; kept in the pair of register a:b
    538
    539
    540
    541
    poke     [counter,a:b,9999]
    542
    543
    544
    545
    ; in my design 'w' is always working reg. which implies that
    546
    ; it cannot be used for normal variables. The following example
    547
    ; uses poke_i_i because the parameter contains two immediate values.
    548
    549
    550
    551
    poke     [counter,9999] ;uses poke_i_i
    552
    553
    554
    555
    ; to be able to choose between a 8,16 or 32 Bit operation, you just
    556
    ; add a void parameter.
    557
    558
    559
    560
    poke     [counter,,9999] ;uses poke_i_v_i
    561
    562
    563
    564
    ; and the same for 32 Bit pokes
    565
    566
    567
    568
    poke     [counter,,,,9999] ;uses poke_i_v_v_v_i
    569
    570

    Loops within macros

    571

    One problem you may have experienced, is that labels defined within macros

    572
    are defined twice if you call the macro for example two times. Now you can
    573
    use labels for macro loops. Loops within macros must end with _%. the
    574
    "%" symbol is replaced by a running number.

    575

    Loop example

    576
    577
    578
    ; Definition of the macro
    579
    580
    581
    582
    .macro   write_8_8
    583
    write_%:
    584
         st      Z+,@0
    585
         dec     @1
    586
         brne    write_%
    587
    .endm
    588
    589
    590
    591
    ; Use in user code
    592
    593
    594
    595
    write   [a,b]
    596
    write   [c,d]
    597
    598
    599
    600
    ; After assembling this code, the result looks like this
    601
    602
    603
    604
    write_1:
    605
         st          Z+,a
    606
         dec         b
    607
         brne        write_1
    608
    write_2:
    609
         st          Z+,c
    610
         dec         d
    611
         brne        write_2
    612
    613
    614

    Warnings and Errors

    615
    616

    Some errors and warnings may confuse you a little bit so we will try to

    617
    clear some frequently asked questions about such cases.

    618

    Constant out of range

    619

    This warning occurs if a value exceeds the byte or word value of a assignment.

    620
    Read the comment posted by Jim Galbraith:

    621

    The expression (~0x80) is a Bitwise Not operation. This

    622
    operator returns the input expression with all its bits
    623
    inverted.  If 0x80 represents -128, then 0x7f, or +127
    624
    should be ok.  If this is considered as a 32-bit expression
    625
    (AVRA internal representation), then it appears to be more
    626
    like oxffffffff-0x80 or 0xffffffff0x80.  The result would then
    627
    be 0xffffff7f.  The assembler would then have to be told or it
    628
    would have to decide, based on context, how much
    629
    significance to assign to the higher bits.  I have also
    630
    encountered such conditions with various assemblers,
    631
    including AVRA.  To make sure the assembler does what I
    632
    really want, I use a construct like 0xff-0x80 or 0xff0x80.
    633
    This way the bit significance cannot extend beyond bit-7 and
    634
    there cannot be any misunderstanding.

    635

    Can’t use .DB directive in data segment

    636
    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

    637
    cannot set ram content at assembly time. The values must be programmed into
    638
    ROM area and at boot read from ROM into RAM. This is up to the user code.
    639
    You can only allocate memory for your variables using labels and the .byte
    640
    directive.

    641
    642
    643
    .dseg
    644
    my_string: .byte 15
    645
    646

    BYTE directive

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

    This directive cannot be used in code or eeprom region because this only

    648
    allocates memory without assgning distinct values to it. Please use .db
    649
    or .dw instead.

    650

    Internal assembler error

    651

    If you get an "Internal assembler error" please contact the project maintainer

    652
    by sending him a code example and a description of your working enviroment.

    653
    654

    AVRA internals

    655
    656

    This section provides thoughts of the avra internal design. I have to admit

    657
    that the code of avra is anything else than clean and optimized. To increase
    658
    the code readability I will try to give you some standards that should improve
    659
    quality. The following standards are similar to what GNU proposes.

    660

    Coding standards

    661

    Tab space is always 2 spaces. The Tab character (ascii 9) is not used.

    662
    if,while,for are always opened on the same line but closed on the next line.
    663
    The closing bracket is in the same column as the first letter of the loop
    664
    directive.

    665
    666
    667
    Example:
    668
    669
    670
    671
        while(i > 0) {
    672
         do_something();
    673
        }
    674
    675
    676

    Credits

    677
    678

    We would like to thank the following people for giving contributions,

    679
    patches and bug reports, as well as suggestions and new ideas.

    680
    681
    682
          Jon Anders Haugum (project founder)
    683
          Burkhard Arenfeld (release 1.2.0)
    684
          Tobias Weber (old maintainer)
    685
          Jerry Jacobs (release 1.3.0)
    686
          Bernt Hembre
    687
          Nils Strøm
    688
          Roberto Biancardi
    689
          Qwerty Jones
    690
          Ben Hitchcock (Maker of the mac port)
    691
          Daniel Drotos
    692
          Laurence Boyd II
    693
          Varuzhan Danielyan
    694
          Laurence Turner
    695
          Eugene R. O'Bryan
    696
          Dmitry Dicky
    697
          Bob Harris (Maker of coff support)
    698
          Tobias Weber (enhanced macro support)
    699
          Lesha Bogdanow
    700
          Jim Galbraith
    701
          Mark Brinicombe
    702
          Igor Nikolayenko
    703
          Peter Hettkamp
    704
          Herb Poppe
    705
          David Burke
    706
          Alexey Pavluchenko
    707
          Alan Probandt
    708
          Mariusz Matuszek
    709
          Arne Rossius
    710
          Marti Tichacek
    711
          Patrick Parity
    712
          Johannes Overmann
    713
          Roland Riegel
    714
          Peter Katzmann
    715
          Donald D. Davis
    716
    717

    And all the anonymous people who submitted patches!

    718

    Thank you for your work and support.

    719
    720

    References

    721
    722
    723
    724
    http://www.suprafluid.com/avra
    725
    http://www.avrfreaks.de
    726
    http://www.atmel.com
    727
    728
    729
    730

    731
    732
    733
    Version 1.3.0
    734
    window.onload>
    735
    736
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    737
    window.onload = function(){asciidoc.footnotes();}
    738
    /*]]>

    739
    740
    741
    742
      
    743
        src="http://www.w3.org/Icons/valid-xhtml11-blue"
    744
        alt="Valid XHTML 1.1" height="31" width="88" />
    745
    746
    747
      
    748
        src="http://jigsaw.w3.org/css-validator/images/vcss-blue"
    749
        alt="Valid CSS!" />
    750
    751
    752
      
    753
           src="http://www.spreadfirefox.com/community/images/affiliates/Buttons/110x32/safer.gif"
    754
           alt="Get Firefox!" />
    755
    756
    757
    758
    759