Jump to content
Sign in to follow this  
danmc77

Writing Tight C Code...

Recommended Posts

Hi,

I've been poking around on the web and have found that there is a great lack of info available with general programming guidelines for optimizing for small code size.

 

How do you optimize your code to conserve precious microcontroller resources?

 

I have only found one site that offers any advise:

http://in4k.untergrund.net/index.php?title...e_for_4kdemos...

 

Thanks,

Dan

Edited by danmc77

Share this post


Link to post
Share on other sites

I discovered that searching on "Efficient C Code" will produce some good info:

 

"Efficient C Code for 8-bit Microcontrollers"

http://www.netrino.com/node/141

 

"Efficient C Code for Eight-Bit MCUs"

http://coe.uncc.edu/~jmconrad/ECGR4101Comm...s%20f-jones.pdf

 

http://www.atmel.com/dyn/resources/prod_do...nts/doc1497.pdf

 

http://www.freescale.com/files/microcontro...note/AN2093.pdf

Share this post


Link to post
Share on other sites

Here are a few of simple but very effective rules that are relevant to SourceBoost and most (if not any) other compilers:

 

- use the smallest data type possible (i.e. code that operates on char variables is much shorter than code tat operates on longs)

- use unsigned data types if possible (code that uses unsigned types is either same or often smaller than the code that uses signed)

- use integer types rather than floats (code that uses floats is much-much bigger than the code that uses integers)

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Hi,

I've been poking around on the web and have found that there is a great lack of info available with general programming guidelines for optimizing for small code size.

 

How do you optimize your code to conserve precious microcontroller resources?

 

I have only found one site that offers any advise:

http://in4k.untergrund.net/index.php?title...e_for_4kdemos...

 

Thanks,

Dan

 

Just an observation, (Sorry, I don't know any guides), but beyond writing good C code, it's obvious to me that improvements could only come from understanding the instruction set of the microprocessor, then establishing how to make the compiler produce the expected code. In short, you'll need to be programming C with your assembler hat on. Leverage this community's expertise; ask for guidance on specific algorithms.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...