[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Accessing function and strings in flash in theATMega
From: |
Robert von Knobloch |
Subject: |
Re: [avr-gcc-list] Accessing function and strings in flash in theATMega 644 |
Date: |
Thu, 05 Feb 2009 09:45:36 +0100 |
User-agent: |
Thunderbird 1.5.0.14 (X11/20060911) |
Weddington, Eric wrote:
>
>
>
>> -----Original Message-----
>> From:
>> address@hidden
>> [mailto:address@hidden
>> org] On Behalf Of Robert von Knobloch
>> Sent: Monday, February 02, 2009 8:49 AM
>> To: address@hidden
>> Subject: [avr-gcc-list] Accessing function and strings in
>> flash in theATMega 644
>>
>>
>
>
>> if (pgm_read_byte((PGM_P)(TESTIMAGE + (IMAGE_SIZE * projnum) +
>> SIGNATURE) != 0))
>>
> <snip>
>
>> Can anyone tell me a: why this does not work and/or what I am assuming
>> that is wrong?
>>
>
> Remember that pgm_read_byte() is a *macro* and not a function. And to top it
> off, that macro generates inline assembly. You have a very complex expression
> in the parameter portion of the macro.
>
> I strongly suggest that you take out the expression and assign it to another
> variable, and just use that variable in place of the pgem_read_byte()
> paramater. As a precaution, take out the call to pgm_read_byte() from the if
> statement.
>
> Like so:
>
> address = (TESTIMAGE + (IMAGE_SIZE * projnum) + SIGNATURE);
> byte = pgm_read_byte(address);
> if (byte != 0)
> {
> // code
> }
>
> See if that helps.
>
> Eric Weddington
>
>
>
Yes Eric, that produces quite sensible code that actually works.
Thank you for the insight. Just two small questions:
1. Why is this 'too complex for the compiler' ?
2. How can I know when the compiler's complexity limit has been reached?
(OK, I don't really expect you to be able to answer. It's just that I
expect a compiler to relieve me of worrying about complex statements.
The only complexity is really (IMAGE_SIZE * projnum), all the rest are
just adding constants - in my simple view).
Many thanks,
Robert