1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3 <!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
4 original version by: Nikos Drakos, CBLU, University of Leeds
5 * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
6 * with significant contributions from:
7 Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
10 <TITLE>5. TIPS</TITLE>
11 <META NAME="description" CONTENT="5. TIPS">
12 <META NAME="keywords" CONTENT="sdccman">
13 <META NAME="resource-type" CONTENT="document">
14 <META NAME="distribution" CONTENT="global">
16 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
17 <META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
18 <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
20 <LINK REL="STYLESHEET" HREF="sdccman.css">
22 <LINK REL="next" HREF="node48.html">
23 <LINK REL="previous" HREF="node38.html">
24 <LINK REL="up" HREF="sdccman.html">
25 <LINK REL="next" HREF="node47.html">
29 <!--Navigation Panel-->
32 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
35 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
38 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
41 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
44 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
46 <B> Next:</B> <A NAME="tex2html952"
47 HREF="node47.html">5.1 Notes on MCS51</A>
48 <B> Up:</B> <A NAME="tex2html946"
49 HREF="sdccman.html">SDCC Compiler User Guide</A>
50 <B> Previous:</B> <A NAME="tex2html940"
51 HREF="node45.html">4.7 Cyclomatic Complexity</A>
52   <B> <A NAME="tex2html948"
53 HREF="node1.html">Contents</A></B>
54   <B> <A NAME="tex2html950"
55 HREF="node61.html">Index</A></B>
58 <!--End of Navigation Panel-->
60 <H1><A NAME="SECTION00060000000000000000">
65 Here are a few guidelines that will help the compiler generate more
66 efficient code, some of the tips are specific to this compiler others
67 are generally good programming practice.
72 <LI>Use the smallest data type to represent your data-value. If it is
73 known in advance that the value is going to be less than 256 then
74 use a 'char' instead of a 'short' or 'int'.</LI>
75 <LI>Use unsigned when it is known in advance that the value is not going
76 to be negative. This helps especially if you are doing division or
78 <LI>NEVER jump into a LOOP.</LI>
79 <LI>Declare the variables to be local whenever possible, especially loop
80 control variables (induction).</LI>
81 <LI>Since the compiler does not do implicit integral promotion, the programmer
82 should do an explicit cast when integral promotion is required.</LI>
83 <LI>Reducing the size of division, multiplication & modulus operations
84 can reduce code size substantially. Take the following code for example.
87 <TT>foobar(unsigned int p1, unsigned char ch)</TT>
91 <TT> unsigned char ch1 = p1 % ch ;</TT>
99 For the modulus operation the variable ch will be promoted to unsigned
100 int first then the modulus operation will be performed (this will
101 lead to a call to support routine _muduint()), and the result will
102 be casted to an int. If the code is changed to
105 <TT>foobar(unsigned int p1, unsigned char ch)</TT>
109 <TT> unsigned char ch1 = (unsigned char)p1 % ch ;</TT>
111 <TT> .... </TT>
117 It would substantially reduce the code generated (future versions
118 of the compiler will be smart enough to detect such optimization oppurtunities).</LI>
123 <!--Table of Child-Links-->
124 <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
127 <LI><A NAME="tex2html953"
128 HREF="node47.html">5.1 Notes on MCS51 memory layout</A>
130 <!--End of Table of Child-Links-->
132 <!--Navigation Panel-->
133 <A NAME="tex2html951"
135 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
136 <A NAME="tex2html945"
138 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
139 <A NAME="tex2html939"
141 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
142 <A NAME="tex2html947"
144 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
145 <A NAME="tex2html949"
147 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
149 <B> Next:</B> <A NAME="tex2html952"
150 HREF="node47.html">5.1 Notes on MCS51</A>
151 <B> Up:</B> <A NAME="tex2html946"
152 HREF="sdccman.html">SDCC Compiler User Guide</A>
153 <B> Previous:</B> <A NAME="tex2html940"
154 HREF="node45.html">4.7 Cyclomatic Complexity</A>
155   <B> <A NAME="tex2html948"
156 HREF="node1.html">Contents</A></B>
157   <B> <A NAME="tex2html950"
158 HREF="node61.html">Index</A></B>
159 <!--End of Navigation Panel-->
162 <BR><I>2001-07-13</I>