SV: [Icc-avr] Bootloader problem

David Brown david_brown at hotpop.com
Fri Nov 2 13:22:29 PST 2007


Michael Dipperstein wrote:
> The source that results in the least amount of AVR instructions depends
> on a number of factors including how PageAddressHigh is allocated and
> the number of available registers.
> 
> More often then not, I get the most compact results that I can think of
> using code that looks like this:
> #define AssignMSB16(var, value)     *((uint8_t *)(&(var)) + 1) = (value)
> #define AssignLSB16(var, value)     *((uint8_t *)(&(var) + 1) - 2) =
> (value)
> 
> AssignLSB16(PageAddressHigh, RxChar());
> AssignMSB16(PageAddressHigh, RxChar());
> 
> The + 1 and then -2 in AssignLSB16 was something I came up with to make
> the compiler generate code the way I thought it should look.  Without
> it, there are some cases where an extra set of registers get used.
> 
> I'll let others chime in about the safety of these kinds of operations.
> 

These macros look perfectly safe to me.  They're a little ugly - all 
such macros are - but hiding them away in a header file lets you keep 
your main source code neat and clear.  They will make your source code a 
little more complicated, but sometimes that's the price you pay to get 
smaller and faster code in critical functions.

mvh.,

David



> -Mike
> 
> -----Original Message-----
> From: icc-avr-bounces at imagecraft.com
> [mailto:icc-avr-bounces at imagecraft.com] On Behalf Of Ira
> Sent: Thursday, November 01, 2007 11:59 PM
> To: icc-avr at imagecraft.com
> Subject: Re: SV: [Icc-avr] Bootloader problem
> 
> At 09:12 AM 11/1/2007, you wrote:
> 
> This is more efficient.
> 
>>         uint8_t tmpLo = RxChar();
>>         PageAddressHigh = tmpLo | (((uint16_t) RxChar()) << 8);
> 
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
> 
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr



More information about the Icc-avr mailing list