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

Can this faster / with less ROM

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



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

Can this faster / with less ROM
PostPosted: Thu Jun 01, 2006 6:20 am     Reply with quote

Hello,

I read that printf instructions use a lot of ROM.
I use a lot of these:

Code:
printf("%c%S%c", COMMANDO_BYTE, WAKE_COMMANDO,0);


Can this be improved?
Ttelmah
Guest







PostPosted: Thu Jun 01, 2006 7:22 am     Reply with quote

Are the bytes constants or variables?.
There should not be a lot in it for a late compiler (the optimiser is fairly 'smart' for this type of simple operation). Where printf, drinks memory, is first, if you do 'simple' numeric outputs, which themselves will involve a lot of divisions etc., and even worse, when you start dealing with float values.The problem is that an understanding of just how much actual 'work' is involved in a tiny statement, like:
printf("%5.2f/n",val);
is often lacking...
Looking at your example, simply changing to:
Code:

printf("%c%S\0", COMMANDO_BYTE, WAKE_COMMANDO);

Will save typically eight bytes.

Best Wishes
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Thu Jun 01, 2006 8:07 am     Reply with quote

constants

Code:
//Commando's
#define TOETS_COMMANDO "KEYS"
#define COMMANDO_BYTE 0xAA
#define DRUK_COMMANDO "PRES"
#define BATTERIJ_COMMANDO "BATT"
#define ADAPTER_COMMANDO "ADAP"
#define WAKE_COMMANDO "WAKE"
#define SLEEP_COMMANDO "SLEE"
#define START_LADEN_COMMANDO "LDNG"
#define EINDE_LADEN_COMMANDO "FULL"
#define ADAPTER_IN_COMMANDO "ADIN"
#define ADAPTER_UIT_COMMANDO "ADUT"
#define ADAPTER_STATUS "ADAS"
#define LAAD_STATUS "LAAD"
#define BRAILLE_COMMANDO "BRAI"
#define BRAILLE_CLEAR "BRCL"
#define BRAILLE_SLEEP "BRSL"
#define BRAILLE_WAKE "BRWA"
#define LADEN_UIT "LDOF"
#define LADEN_AAN "LDON"
#define MAX1797_AAN "5VON"
#define MAX1797_UIT "5VOF"
#define BOOT_OK "BOOT"
#define UITZETTEN_E3 "E3OF"
#define BOOT_OK_COMMANDO "BTOK"
#define UIT_TIMER "OFTI"
#define TOETSKLIK "KLIK"
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Thu Jun 01, 2006 8:22 am     Reply with quote

Ttelmah wrote:
Are the bytes constants or variables?.
There should not be a lot in it for a late compiler (the optimiser is fairly 'smart' for this type of simple operation). Where printf, drinks memory, is first, if you do 'simple' numeric outputs, which themselves will involve a lot of divisions etc., and even worse, when you start dealing with float values.The problem is that an understanding of just how much actual 'work' is involved in a tiny statement, like:
printf("%5.2f/n",val);
is often lacking...
Looking at your example, simply changing to:
Code:

printf("%c%S\0", COMMANDO_BYTE, WAKE_COMMANDO);

Will save typically eight bytes.

Best Wishes


With that, the last '0' is not being sent. (And I need to..)
Ttelmah
Guest







PostPosted: Thu Jun 01, 2006 9:49 am     Reply with quote

Yes, you cannot send a trailing '0' this way (the only character you can't), since it is seen as the 'end' of the printf string. The other constants can be, but I doubt if you will save anything. The compiler is bright enough to know that with constants, it just has to load the value, and send it.
If you only have to send a couple of constant values, you are not going to save anything. If the list is a lot longer, there are other tricks that can help (the overhead of fetching a list from ROM, is probably equivalent to about five values - above this length, this will be better, but below this length it'll be worse, so using this technique only becomes worthwhile for longer messages).

Best Wishes
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Jun 01, 2006 10:13 am     Reply with quote

Cristophe, I see all your commandos are four-letter words (no pun intended :-) , so you can perhaps organize them into a lookup table, and make a custom printf routine, that would take only an index into this table as a parameter.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Fri Jun 02, 2006 6:43 am     Reply with quote

libor,

could you make a small example? I don't understand what you mean.

thx for the input all
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