PDA

View Full Version : code size VS speed optimization setting?



Kamikaze47
- 28th April 2008, 09:42
Does PBP have a code size vs. speed optimization setting? I know some compilers have this option but I wasn't sure about PBP.

Basically i need the compiled code to be as small as possible, but execution speed isn't overly critical.

Is there a setting for this?

Thanks

mackrackit
- 28th April 2008, 10:21
I have never heard of a setting like for that. I think it all depends on the person using the keyboard.

Small code is done with many sub routines. Say you are using an ADC. If you need to read the ADC many times, have a GOSUB or GOTO a LABEL with everything in that routine instead of rewriting it several times. If that routine has five lines to read the ADC and write it to EEPROM or some place else, then the one GUSUB here and there will end up saving some lines of code. In other words, do not repeat yourself.
HTH

Kamikaze47
- 28th April 2008, 10:33
yeah ive written a program nearly 3000 lines long, and ive hit the end of the 32k of code space my PIC has. I pulled all the strings out into EEPROM and that saved some space, but im likely to run out again soon. I've done the most obvious things to save space.

*edit* i guess the only thing left to do is go thru all 3000 lines looking for where i can make it more efficient... *sigh* that will be a chore

mackrackit
- 28th April 2008, 10:54
Just a thought...
Move some of the routines over to another PIC, Maybe something that has some heavy calculations. PIC#1 sends data to PIC#2 for calcs, when finished PIC#2 sends data back to PIC#1. Sort of like an interrupt.

skimask
- 28th April 2008, 13:48
yeah ive written a program nearly 3000 lines long, and ive hit the end of the 32k of code space my PIC has. I pulled all the strings out into EEPROM and that saved some space, but im likely to run out again soon. I've done the most obvious things to save space.
*edit* i guess the only thing left to do is go thru all 3000 lines looking for where i can make it more efficient... *sigh* that will be a chore
Have you tried moving the most commonly used variables to BANK 0? (only applies if you're using a 16Fxxx series PIC, doesn't do anything on an 18Fxxx series)

Kamikaze47
- 28th April 2008, 13:56
using an 18F4550

I would just get a pic with more code space. but i need the USB functionality of the 4550.

skimask
- 28th April 2008, 14:00
using an 18F4550
I would just get a pic with more code space. but i need the USB functionality of the 4550.

Repeat...Until uses less space than a For...Next, about 3 bytes for each one...

Multiplies and Divides by power's of 2 can be replaced by shifts << and >> ...

For...Next loop that are (for instance) "0 to 7" take up less space than "1 to 8", again, only a few worth...

Kamikaze47
- 28th April 2008, 14:38
thanks for the tips

i'll go thru my code

*cringe*