[Top][All Lists]

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

Re: [avr-gcc-list] efficiency of assigning bits

From: Jesper Hansen
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Mon, 14 Mar 2005 21:20:13 +0100

Actually, it's more efficient to code it as two separate statements, *if* the register is one of the first 32 in the chip's register space. Two statements will result in 2 sbi or cbi instructions, while a single statement will result in a read-modify-write sequence of 3 instructions.

If the register is outside that range, then yes, it is more efficient to do it as a single statement, because sbi/cbi don't work and you're back to a read-modify-write sequence for each of the two statements, resulting in 6 instructions.

I went around on this several times while trying to shave one instruction at a time on a project that's filled the 1024-byte code space (512 instructions) of an ATtiny15 to 99+%. Waiting for ATtiny45 samples......

An often overlooked solution, especially with ports that changes in a determined way, is to read the contents of the port at an early stage, then use that as a base for manipulation.
 register uint8_t pval = PORTA;
- - PORTA = pval | 0x23; - PORTA = pval;

e.t.c., you get the idea
This will result in one or two cycle (and instuction) sequnces.
Can save quite a few bytes in the right code.


reply via email to

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