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

Why CCS generates large code

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



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

Why CCS generates large code
PostPosted: Wed Jul 07, 2010 3:19 pm     Reply with quote

Hello,

I have a question that I could not find any answer.
I add the code part and its assembly output. How can I force CCS to compile smaller code? PIC is 12F675 and v4.107

Code:

#use delay(clock=4M,RESTART_WDT)
#byte gpio = getenv("SFR:GPIO")
#bit  STX  = gpio.5

#use fast_io(A)

int8  i;
int32 TheData=0xAA55;
.
.
.
   for(i=0;i<18;i++)
   {
      if(bit_test(TheData,i))
         STX=1;
      else
         STX=0;
      delay_us(100);

      STX=1;
      delay_us(50);
      STX=0;
      delay_us(50);
   }


Code:
....................    for(i=0;i<18;i++)
01D2:  CLRF   2E
01D3:  MOVF   2E,W
01D4:  SUBLW  11
01D5:  BTFSS  03.0
01D6:  GOTO   203
....................    {
....................       if(bit_test(TheData,i))
01D7:  MOVF   36,W
01D8:  MOVWF  23
01D9:  MOVF   35,W
01DA:  MOVWF  22
01DB:  MOVF   34,W
01DC:  MOVWF  21
01DD:  MOVF   33,W
01DE:  MOVWF  20
01DF:  MOVF   2E,W
01E0:  MOVWF  37
01E1:  BTFSC  03.2
01E2:  GOTO   1EA
01E3:  BCF    03.0
01E4:  RRF    23,F
01E5:  RRF    22,F
01E6:  RRF    21,F
01E7:  RRF    20,F
01E8:  DECFSZ 37,F
01E9:  GOTO   1E3
01EA:  BTFSS  20.0
01EB:  GOTO   1EE
....................          STX=1;
01EC:  BSF    05.5
....................       else
01ED:  GOTO   1EF
....................          STX=0;
01EE:  BCF    05.5
....................       delay_us(100);
01EF:  CLRWDT
01F0:  MOVLW  20
01F1:  MOVWF  20
01F2:  DECFSZ 20,F
01F3:  GOTO   1F2
01F4:  GOTO   1F5
.................... 
....................       STX=1;
01F5:  BSF    05.5
....................      delay_us(50);
01F6:  CLRWDT
01F7:  MOVLW  10
01F8:  MOVWF  20
01F9:  DECFSZ 20,F
01FA:  GOTO   1F9
....................      STX=0;
01FB:  BCF    05.5
....................      delay_us(50);
01FC:  CLRWDT
01FD:  MOVLW  10
01FE:  MOVWF  20
01FF:  DECFSZ 20,F
0200:  GOTO   1FF
....................    }
0201:  INCF   2E,F
0202:  GOTO   1D3


Thanks
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 3:23 pm     Reply with quote

HA! you should see the output of some other compilers...

That looks pretty decent although others might have some suggestions -- most likely you'll have to write your own assembly..

But that looks pretty good.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 5:00 pm     Reply with quote

You need to remember that the device is an 8bit MCU and you are manipulating a 32bit variable. Just in the bit_test() routine, nine extra instructions are needed to manipulate this. Change it to an 8bit variable and you will get nine fewer instructions for that command.

Ronald
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 5:42 pm     Reply with quote

Here is a version where you can keep the int32 and shave of 10 instructions:
Code:
   for(i=0;i<18;i++)
   {
      STX = shift_right(&TheData, sizeof(TheData), 1);
      delay_us(100);

      STX=1;
      delay_us(50);
      STX=0;
      delay_us(50);
   }
Code:
....................       STX = shift_right(&TheData, sizeof(TheData), 1);
004E:  BCF    PMDATH.5
004F:  BSF    STATUS.C
0050:  RRF    TheData+3,F
0051:  RRF    TheData+2,F
0052:  RRF    TheData+1,F
0053:  RRF    TheData,F
0054:  BTFSC  STATUS.C
0055:  BSF    PMDATH.5
....................       delay_us(100);

It modifies the contents of TheData, but for many applications this is no problem.

And because you are only using 18 of the 32 bits, it can be reduced by 1 more instruction when you shift only 3 bytes (24 bits) instead of 4 bytes (32 bits).:
Code:
      STX = shift_right( ((int8*) &TheData) + 1, 3, 1);


Last edited by ckielstra on Wed Jul 07, 2010 5:55 pm; edited 1 time in total
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 5:47 pm     Reply with quote

@rnielsen, yeah, I understand, but I have to have 18 bit data :(

@ckielstra,
But I'm sending first 18 bit of TheData and it's problem to be modified, right?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 5:58 pm     Reply with quote

FFT wrote:
But I'm sending first 18 bit of TheData and it's problem to be modified, right?
From the small code fragment you have posted we can not see if this is a problem or not. It all depends on what you are doing with TheData variable after you have transmitted the contents. Most likely you are going to read new data from your sensor and then it doesn't matter.
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