Reshaped doc's
[fw/sdcc] / doc / sdccman.html / node47.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
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 -->
8 <HTML>
9 <HEAD>
10 <TITLE>5.1 Notes on MCS51 memory layout</TITLE>
11 <META NAME="description" CONTENT="5.1 Notes on MCS51 memory layout">
12 <META NAME="keywords" CONTENT="sdccman">
13 <META NAME="resource-type" CONTENT="document">
14 <META NAME="distribution" CONTENT="global">
15
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">
19
20 <LINK REL="STYLESHEET" HREF="sdccman.css">
21
22 <LINK REL="previous" HREF="node46.html">
23 <LINK REL="up" HREF="node46.html">
24 <LINK REL="next" HREF="node48.html">
25 </HEAD>
26
27 <BODY >
28 <!--Navigation Panel-->
29 <A NAME="tex2html964"
30  HREF="node48.html">
31 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
32 <A NAME="tex2html958"
33  HREF="node46.html">
34 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
35 <A NAME="tex2html954"
36  HREF="node46.html">
37 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
38 <A NAME="tex2html960"
39  HREF="node1.html">
40 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
41 <A NAME="tex2html962"
42  HREF="node61.html">
43 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
44 <BR>
45 <B> Next:</B> <A NAME="tex2html965"
46  HREF="node48.html">6. Retargetting for other</A>
47 <B> Up:</B> <A NAME="tex2html959"
48  HREF="node46.html">5. TIPS</A>
49 <B> Previous:</B> <A NAME="tex2html955"
50  HREF="node46.html">5. TIPS</A>
51  &nbsp <B>  <A NAME="tex2html961"
52  HREF="node1.html">Contents</A></B> 
53  &nbsp <B>  <A NAME="tex2html963"
54  HREF="node61.html">Index</A></B> 
55 <BR>
56 <BR>
57 <!--End of Navigation Panel-->
58
59 <H2><A NAME="SECTION00061000000000000000">
60 5.1 Notes on MCS51 memory layout</A>
61 </H2>
62
63 <P>
64 The 8051 family of micro controller have a minimum of 128 bytes of
65 internal memory which is structured as follows
66 <BR>
67
68 <BR>
69 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7
70 to R7 
71 <BR>
72 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
73 <BR>
74 - Bytes 30-7F - 60 bytes for general purpose use.
75 <BR>
76
77 <BR>
78 Normally the SDCC compiler will only utilise the first bank of registers,
79 but it is possible to specify that other banks of registers should
80 be used in interrupt routines. By default, the compiler will place
81 the stack after the last bank of used registers, i.e. if the first
82 2 banks of registers are used, it will position the base of the internal
83 stack at address 16 (0X10). This implies that as the stack grows,
84 it will use up the remaining register banks, and the 16 bytes used
85 by the 128 bit variables, and 60 bytes for general purpose use.
86
87 <P>
88 By default, the compiler uses the 60 general purpose bytes to hold
89 &#34;near data&#34;. The compiler/optimiser may also declare
90 some Local Variables in this area to hold local data. 
91
92 <P>
93 If any of the 128 bit variables are used, or near data is being used
94 then care needs to be taken to ensure that the stack does not grow
95 so much that it starts to over write either your bit variables or
96 &#34;near data&#34;. There is no runtime checking to prevent
97 this from happening.
98
99 <P>
100 The amount of stack being used is affected by the use of the &#34;internal
101 stack&#34; to save registers before a subroutine call is made
102 (-stack-auto will declare parameters and local variables on the stack)
103 and the number of nested subroutines.
104
105 <P>
106 If you detect that the stack is over writing you data, then the following
107 can be done. -xstack will cause an external stack to be used for
108 saving registers and (if -stack-auto is being used) storing parameters
109 and local variables. However this will produce more code which will
110 be slower to execute. 
111
112 <P>
113  
114 -stack-loc will allow you specify the start of the stack, i.e. you
115 could start it after any data in the general purpose area. However
116 this may waste the memory not used by the register banks and if the
117 size of the &#34;near data&#34; increases, it may creep
118 into the bottom of the stack.
119
120 <P>
121  
122 -stack-after-data, similar to the -stack-loc, but it automatically
123 places the stack after the end of the &#34;near data&#34;.
124 Again this could waste any spare register space.
125
126 <P>
127  
128 -data-loc allows you to specify the start address of the near data.
129 This could be used to move the &#34;near data&#34; further
130 away from the stack giving it more room to grow. This will only work
131 if no bit variables are being used and the stack can grow to use the
132 bit variable space.
133 <BR>
134
135 <BR>
136 Conclusion.
137 <BR>
138
139 <BR>
140 If you find that the stack is over writing your bit variables or &#34;near
141 data&#34; then the approach which best utilised the internal
142 memory is to position the &#34;near data&#34; after the
143 last bank of used registers or, if you use bit variables, after the
144 last bit variable by using the -data-loc, e.g. if two register banks
145 are being used and no bit variables, -data-loc 16, and use the -stack-after-data
146 option.
147
148 <P>
149 If bit variables are being used, another method would be to try and
150 squeeze the data area in the unused register banks if it will fit,
151 and start the stack after the last bit variable.
152
153 <P>
154 <HR>
155 <!--Navigation Panel-->
156 <A NAME="tex2html964"
157  HREF="node48.html">
158 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
159 <A NAME="tex2html958"
160  HREF="node46.html">
161 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
162 <A NAME="tex2html954"
163  HREF="node46.html">
164 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
165 <A NAME="tex2html960"
166  HREF="node1.html">
167 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
168 <A NAME="tex2html962"
169  HREF="node61.html">
170 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
171 <BR>
172 <B> Next:</B> <A NAME="tex2html965"
173  HREF="node48.html">6. Retargetting for other</A>
174 <B> Up:</B> <A NAME="tex2html959"
175  HREF="node46.html">5. TIPS</A>
176 <B> Previous:</B> <A NAME="tex2html955"
177  HREF="node46.html">5. TIPS</A>
178  &nbsp <B>  <A NAME="tex2html961"
179  HREF="node1.html">Contents</A></B> 
180  &nbsp <B>  <A NAME="tex2html963"
181  HREF="node61.html">Index</A></B> 
182 <!--End of Navigation Panel-->
183 <ADDRESS>
184 <I>Johan Knol</I>
185 <BR><I>2001-07-13</I>
186 </ADDRESS>
187 </BODY>
188 </HTML>