avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] It is more than: .byte SYMA - SYMB


From: Erik Christiansen
Subject: Re: [avr-gcc-list] It is more than: .byte SYMA - SYMB
Date: Fri, 12 Sep 2003 19:14:52 +1000
User-agent: Mutt/1.3.28i

On Fri, Sep 12, 2003 at 08:52:00AM +0200, Joerg Wunsch wrote:
> >c: .string  "Hello World"
> >   .align 2
> 
> Are you saying that the .align 2 solves the problem even in
> cases when the data were already properly aligned, just the
> assembler didn't know about this?

Sorry for not explaining it better, but it's actually the opposite. If
_no_ .align is used, then the constant expression evaluates OK. (If the
string is of odd length, though, instructions end up on odd byte
addresses. When this is linked, avr-ld complains "internal error: out of
range error" instead of flagging an alignment error, so that's worth
watching out for.)

Inserting the .align seems to make the assembler aware that the linker
may need to pad, depending on the original alignment and the string
length. As I figure it, the difference (d-c) is only truly non-constant
if the original alignment is unknown, but this also triggers the "Error:
constant value required" message:

   .align 2          
c: .ascii  "Hello World"
   .align 2
d: ldi   XH,pm_hi8(d - c)

The only way to avoid both error messages seems to be to manually make
all strings of even length. (Including the \0 implicit in .asciiz and
.string)

How to convince the assembler that data space differences are constant,
still eludes me:

   ldi   XH,pm_hi8(bb - aa)      <- No error!!! (But it's not progmem)
   ldd   r16,Y+(bb - aa)         <- Error: constant value required

   .section .bss,"a"
   .org 0
aa: .space 32
bb:

IIRC, you've already observed that something like:

   ldd   r16,Y+lo8(bb - aa)

only adds "Error: garbage at end of line"

I've resorted to hand-generating constants for these offsets. I suppose
I could wrap them in a struct generating macro, but it would still be
necessary to refer to the offsets, not the member names, in code. (Yuk)

With powerpc-linux-as, which is also gas, I've used:

   lwz   r0,boot_check - bsda + 4(r13)

where both labels are data addresses, which is what we're trying to do.
(The last term is an additional fixed offset plus an index register.)
Maybe there are ideas, and even useful code, to be found in the powerpc
part of the binutils source tree?

Regards,
Erik




reply via email to

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