CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Unnecessary overhead by Compiler

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bennyboos



Joined: 17 Nov 2005
Posts: 30
Location: Chester UK

View user's profile Send private message

Unnecessary overhead by Compiler
PostPosted: Fri Jun 09, 2006 3:22 am     Reply with quote

I have noticed that the compiler occasionaly inserts additional code that in some instances is useless or in my case unwanted because I want to keep things as compact as possible (i.e. a bootloader).

For example, the following code
Code:
#include <16F819.h>

void main(void) {
   setup_adc_ports(ALL_ANALOGS);
   while(1) restart_wdt();
}

produces the following (dis)assembly
Code:
---  C:\Hiykon\Genial\Ccode\HarvesterMk2\PumpBoard-PIC16F819-Boot\Version2\main.c  ---------------
1:                 #include <16F819.h>
   000    3000     MOVLW 0
   001    008A     MOVWF 0xa
   002    2804     GOTO 0x4
   003    0000     NOP
2:                 
3:                 void main(void) {
   004    0184     CLRF 0x4
   005    301F     MOVLW 0x1f
   006    0583     ANDWF 0x3, F
   007    1683     BSF 0x3, 0x5
   008    141F     BSF 0x1f, 0
   009    149F     BSF 0x1f, 0x1
   00A    151F     BSF 0x1f, 0x2
   00B    119F     BCF 0x1f, 0x3
   00C    1283     BCF 0x3, 0x5
4:                    setup_adc_ports(ALL_ANALOG);
   00D    1683     BSF 0x3, 0x5
   00E    101F     BCF 0x1f, 0
   00F    109F     BCF 0x1f, 0x1
   010    111F     BCF 0x1f, 0x2
   011    119F     BCF 0x1f, 0x3
   012    1283     BCF 0x3, 0x5
5:                    while(1) restart_wdt();
   013    0064     CLRWDT
   014    2813     GOTO 0x13
   015    0063     SLEEP

From line 007-00C the compiler sets all of the ADC ports to digital without my asking it. While this might be regarded as convenient it seems a bit wasteful since in this example, the first thing I wish to do is set them all to analog.

Does anyone know a way or option setting to stop the compiler being too helpful (wasteful)?

Bennyboos
Douglas Richard



Joined: 08 Sep 2003
Posts: 49
Location: Concord NH

View user's profile Send private message Send e-mail Visit poster's website

reply Unnecessary overhead by Compiler
PostPosted: Fri Jun 09, 2006 6:14 am     Reply with quote

set up your analog ports manually. That is instead of using setup_adc_ports(), locate the SFR needed and manipulate them yourself. Saves code but not very portable.
bennyboos



Joined: 17 Nov 2005
Posts: 30
Location: Chester UK

View user's profile Send private message

Unnecessary overhead by Compiler
PostPosted: Fri Jun 09, 2006 6:40 am     Reply with quote

Hi Doug,
I've already tried this method but the compiler still insists on setting bits in adcon1 before it gets as far as my C-code.
E.G.
Code:
#include <16F819.h>

#byte adcon1 = 0x9F
void main(void) {
   adcon1 &= 0xF0;
   while(1) restart_wdt();
}

Produces the following disassembly
Code:
---  C:\Hiykon\Genial\Ccode\HarvesterMk2\PumpBoard-PIC16F819-Boot\Version2\main.c  ---------------
1:                 #include <16F819.h>
   000    3000     MOVLW 0
   001    008A     MOVWF 0xa
   002    2804     GOTO 0x4
   003    0000     NOP
2:                 
3:                 #byte adcon1 = 0x9F
4:                 void main(void) {
   004    0184     CLRF 0x4
   005    301F     MOVLW 0x1f
   006    0583     ANDWF 0x3, F
   007    1683     BSF 0x3, 0x5
   008    141F     BSF 0x1f, 0
   009    149F     BSF 0x1f, 0x1
   00A    151F     BSF 0x1f, 0x2
   00B    119F     BCF 0x1f, 0x3
   00C    1283     BCF 0x3, 0x5
5:                    adcon1 &= 0xF0;
   00D    30F0     MOVLW 0xf0
   00E    1683     BSF 0x3, 0x5
   00F    059F     ANDWF 0x1f, F
   010    1283     BCF 0x3, 0x5
6:                    while(1) restart_wdt();
   011    0064     CLRWDT
   012    2811     GOTO 0x11
   013    0063     SLEEP

i.e. we still seem to have lines 007 to 00C which are totally unnecessary.
There also seems to a lot of wasted fiddling of bank select???

Ben
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Unnecessary overhead by Compiler
PostPosted: Fri Jun 09, 2006 7:09 am     Reply with quote

bennyboos wrote:
Hi Doug,
I've already tried this method but the compiler still insists on setting bits in adcon1 before it gets as far as my C-code.
E.G.
Code:
#include <16F819.h>

#byte adcon1 = 0x9F
void main(void) {
   adcon1 &= 0xF0;
   while(1) restart_wdt();
}

Produces the following disassembly
Code:
---  C:\Hiykon\Genial\Ccode\HarvesterMk2\PumpBoard-PIC16F819-Boot\Version2\main.c  ---------------
1:                 #include <16F819.h>
   000    3000     MOVLW 0
   001    008A     MOVWF 0xa
   002    2804     GOTO 0x4
   003    0000     NOP
2:                 
3:                 #byte adcon1 = 0x9F
4:                 void main(void) {
   004    0184     CLRF 0x4
   005    301F     MOVLW 0x1f
   006    0583     ANDWF 0x3, F
   007    1683     BSF 0x3, 0x5
   008    141F     BSF 0x1f, 0
   009    149F     BSF 0x1f, 0x1
   00A    151F     BSF 0x1f, 0x2
   00B    119F     BCF 0x1f, 0x3
   00C    1283     BCF 0x3, 0x5
5:                    adcon1 &= 0xF0;
   00D    30F0     MOVLW 0xf0
   00E    1683     BSF 0x3, 0x5
   00F    059F     ANDWF 0x1f, F
   010    1283     BCF 0x3, 0x5
6:                    while(1) restart_wdt();
   011    0064     CLRWDT
   012    2811     GOTO 0x11
   013    0063     SLEEP

i.e. we still seem to have lines 007 to 00C which are totally unnecessary.
There also seems to a lot of wasted fiddling of bank select???

Ben


Remember that C is not as compact and ASM. Some things you will just have to live with.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 09, 2006 11:42 am     Reply with quote

I don't think there is a way to prevent the compiler from inserting
the startup code, in which it sets Port A to all digital i/o. What is
needed, is something like a #build(noinit) statement. This would
stop the compiler from adding any init code to main(). Someone
would have to send a request to CCS and ask them to add this.


With respect to the inefficient method of initializing the ADCON register,
CCS started doing this in late 2003. Before that time, they used to
init ADCON with one byte-wide instruction. I sent one or more emails
to them complaining about it, but they ignored them all.
http://www.ccsinfo.com/forum/viewtopic.php?t=19616
Ttelmah
Guest







PostPosted: Fri Jun 09, 2006 2:44 pm     Reply with quote

There is a 'trick', if you have PCW. Just use the device editor, and set the number of ADC channels to '0'. The compiler then no longer generates the ADC initialisation code. The listing file (with the manual setting of adcon1), becomes:
Code:

0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   004
0003:  NOP
.................... #include <16F819.h>
.................... //////// Standard Header file for the PIC16F819 device ////////////////
.................... #device PIC16F819
.................... #list
....................
....................
.................... #byte adcon1 = 0x9F
....................
.................... void main(void) {
0004:  CLRF   04
0005:  MOVLW  1F
0006:  ANDWF  03,F
....................    adcon1 &= 0xF0;
0007:  MOVLW  F0
0008:  BSF    03.5
0009:  ANDWF  1F,F
....................    while(1) restart_wdt();
000A:  CLRWDT
000B:  GOTO   00A
.................... }
000C:  SLEEP

Brute force, but it does work!...

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group