[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] forcing address

From: Bruce D. Lightner
Subject: Re: [avr-gcc-list] forcing address
Date: Wed, 21 Aug 2002 10:18:10 -0700


> I am writing an assembly file to include some time, and
> sequence sensitive code. I have a lookup table that I defined
> in the .s file. I cannot get the compiler to place the lookup
> table at a given location. I want the table to be aligned
> with a boundary like 0x100. I could shorten the code if I
> could accomplish it, plus I don't like not being able to
> accomplish my objective.
> I'm using:
> .section .text .org 0x100
> sine_tbl: .byte . . . . . . . . . . . . . . . . . . . . . . . . . .
> . . . . . . . . . . . . . .  ; 32 bytes
> The code is placed anywhere, but not where I want it.
> Is it possible to do what I'm trying?
> I have searched for a document listing and showing the usage of the 
> following:
> .org
> .section
> .text
> .code
> .word
> .byte
> And whatever else there is.
> Thank You.
> Marlin

What you want to do is not unreasonable.  In fact, the nice folks at "GNU,
Inc." have provided for this!

In AVR assembly, the assembly code you should use is something like the

             .section .text
             .align 8
             .global sine_tbl
   sine_tbl: .byte 0, ... 

The key is ".align 8".  The "8" specifies the number of zeros in the
low-order bits of the location counter...for the AVR gcc toolset anyway.  On
other systems, the "8" MAY specify "byte alignment" instead, a very
different thing!

So, probably a better way is to use ".balign", which always behaves the

             .section .text
             .balign 256
             .global sine_tbl
   sine_tbl: .byte 0, ...

This specifies that your sine look-up table be "byte-aligned" on a 256-byte
boundary.  You can look in the linker "map file" using the global symbol to
verify that this works.

The "bad news" is that this will waste between 0 and 255 bytes of AVR
program memory when it is linked into a ROM image.  How much program code
space is wasted simply depends upon when and where the linker picks up the
object module containing your sine look-up table.  To the best of my
knowledge, you have no direct control over this process with the GNU
linker.  If code-space is tight, then you may have to "play around" by
changing the order in which your object modules are linked.

There is no doubt some way to do this in C using __attribute__ and
"aligned", but I can't seem to make it work on my copy of avr-gcc
(v2.95.2).  I get an error of the form:

   Warning: alignment of `sine_tbl' is greater than maximum object
   file alignment. Using 1.

Maybe one of the many "new and improved" versions of avr-gcc are better. 
Me?  I like to stay with the compiler bugs that I know (and love) for as
long as I can stand it! :-)

Best regards,


 Bruce D. Lightner
 Lightner Engineering
 La Jolla, California
 Email: address@hidden
 URL: http://www.lightner.net/lightner/bruce/
avr-gcc-list at http://avr1.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]