<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2008 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>3.8 Overlaying</TITLE> <META NAME="description" CONTENT="3.8 Overlaying"> <META NAME="keywords" CONTENT="sdccman"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2008"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="sdccman.css"> <LINK REL="next" HREF="node67.html"> <LINK REL="previous" HREF="node65.html"> <LINK REL="up" HREF="node37.html"> <LINK REL="next" HREF="node67.html"> </HEAD> <BODY > <!--Navigation Panel--> <A NAME="tex2html1668" HREF="node67.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html1662" HREF="node37.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html1656" HREF="node65.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html1664" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html1666" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html1669" HREF="node67.html">3.9 Interrupt Service Routines</A> <B> Up:</B> <A NAME="tex2html1663" HREF="node37.html">3. Using SDCC</A> <B> Previous:</B> <A NAME="tex2html1657" HREF="node65.html">3.7 Parameters & Local</A> <B> <A NAME="tex2html1665" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html1667" HREF="node191.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H1><A NAME="SECTION00480000000000000000"></A><A NAME="sub:Overlaying"></A><A NAME="1647"></A> <BR> 3.8 Overlaying </H1> <P> For non-reentrant<A NAME="1648"></A> functions SDCC will try to reduce internal ram space usage by overlaying parameters and local variables of a function (if possible). Parameters and local variables<A NAME="1649"></A> of a function will be allocated to an overlayable segment if the function has <I>no other function calls and the function is non-reentrant and the memory model<A NAME="1650"></A> is small.</I> If an explicit storage class<A NAME="1651"></A> is specified for a local variable, it will NOT be overlaid. <P> Note that the compiler (not the linkage editor) makes the decision for overlaying the data items. Functions that are called from an interrupt service routine should be preceded by a #pragma nooverlay<A NAME="1653"></A> if they are not reentrant. <P> Also note that the compiler does not do any processing of inline assembler code, so the compiler might incorrectly assign local variables and parameters of a function into the overlay segment if the inline assembler code calls other c-functions that might use the overlay. In that case the #pragma nooverlay should be used. <P> Parameters and local variables of functions that contain 16 or 32 bit multiplication<A NAME="1654"></A> or division<A NAME="1655"></A> will NOT be overlaid since these are implemented using external functions, e.g.: <BLOCKQUOTE> <TT>#pragma save </TT> <BR><TT>#pragma nooverlay<A NAME="1658"></A> </TT> <BR><TT>void set_error(unsigned char errcd) </TT> <BR><TT>{</TT> <BR><TT> P3 = errcd;</TT> <BR><TT>} </TT> <BR><TT>#pragma restore </TT> <BR> <BR><TT>void some_isr () __interrupt<A NAME="1665"></A> (2)</TT> <BR><TT>{</TT> <BR><TT> ...</TT> <BR><TT> set_error(10);</TT> <BR><TT> ... </TT> <BR><TT>}</TT> </BLOCKQUOTE> In the above example the parameter <I>errcd</I> for the function <I>set_error</I> would be assigned to the overlayable segment if the #pragma nooverlay was not present, this could cause unpredictable runtime behavior when called from an interrupt service routine. The #pragma nooverlay ensures that the parameters and local variables for the function are NOT overlaid. <P><P> <BR> <P> <HR> <!--Navigation Panel--> <A NAME="tex2html1668" HREF="node67.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html1662" HREF="node37.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html1656" HREF="node65.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html1664" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html1666" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html1669" HREF="node67.html">3.9 Interrupt Service Routines</A> <B> Up:</B> <A NAME="tex2html1663" HREF="node37.html">3. Using SDCC</A> <B> Previous:</B> <A NAME="tex2html1657" HREF="node65.html">3.7 Parameters & Local</A> <B> <A NAME="tex2html1665" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html1667" HREF="node191.html">Index</A></B> <!--End of Navigation Panel--> <ADDRESS> 2011-03-20 </ADDRESS> </BODY> </HTML>