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 CCS Technical Support

Ideas for packing in more code into program memory

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



Joined: 08 Sep 2003
Posts: 492
Location: India

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

Ideas for packing in more code into program memory
PostPosted: Thu May 04, 2006 8:18 am     Reply with quote

Hi,

Is the modular approach the best method for increasing ROM space ??

I find that calling a function a number of times reduces ROM space..
Also how does breaking up a large function into smaller ones improves matters ??

thanks
arunb
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu May 04, 2006 8:42 am     Reply with quote

Compare the assembled code for the following.
Code:
   for (x=0;x<5;x++)
   {  x=y;
   }
   
   x=0;
   x=1;
   x=2;
   x=3;
   x=4;
   
   for (x=0;x<10;x++)
   {  x=y;
   }
   
   x=0;
   x=1;
   x=2;
   x=3;
   x=4;
   x=5;
   x=6;
   x=7;
   x=8;
   x=9;


Code:
....................    Int8 x,y;
....................
....................    for (x=0;x<5;x++)
0680:  CLRF   4B
0682:  MOVF   4B,W
0684:  SUBLW  04
0686:  BNC   0690
....................    {  x=y;
0688:  MOVFF  4C,4B
....................    }
068C:  INCF   4B,F
068E:  BRA    0682
....................
....................    x=0;
0690:  CLRF   4B
....................    x=1;
0692:  MOVLW  01
0694:  MOVWF  4B
....................    x=2;
0696:  MOVLW  02
0698:  MOVWF  4B
....................    x=3;
069A:  MOVLW  03
069C:  MOVWF  4B
....................    x=4;
069E:  MOVLW  04
06A0:  MOVWF  4B
....................
....................    for (x=0;x<10;x++)
06A2:  CLRF   4B
06A4:  MOVF   4B,W
06A6:  SUBLW  09
06A8:  BNC   06B2
....................    {  x=y;
06AA:  MOVFF  4C,4B
....................    }
06AE:  INCF   4B,F
06B0:  BRA    06A4
....................
....................    x=0;
06B2:  CLRF   4B
....................    x=1;
06B4:  MOVLW  01
06B6:  MOVWF  4B
....................    x=2;
06B8:  MOVLW  02
06BA:  MOVWF  4B
....................    x=3;
06BC:  MOVLW  03
06BE:  MOVWF  4B
....................    x=4;
06C0:  MOVLW  04
06C2:  MOVWF  4B
....................    x=5;
06C4:  MOVLW  05
06C6:  MOVWF  4B
....................    x=6;
06C8:  MOVLW  06
06CA:  MOVWF  4B
....................    x=7;
06CC:  MOVLW  07
06CE:  MOVWF  4B
....................    x=8;
06D0:  MOVLW  08
06D2:  MOVWF  4B
....................    x=9;
06D4:  MOVLW  09
06D6:  MOVWF  4B


If you start looking at the assembled code from the C code you write you will get a feel for the way to make code run fast ,use less space or easy to read. It is a big advantage to know how the C you write will assemble.
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