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>3.9 Naked Functions</TITLE>
11 <META NAME="description" CONTENT="3.9 Naked Functions">
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="node29.html">
23 <LINK REL="previous" HREF="node27.html">
24 <LINK REL="up" HREF="node19.html">
25 <LINK REL="next" HREF="node29.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="tex2html669"
47 HREF="node29.html">3.10 Functions using private</A>
48 <B> Up:</B> <A NAME="tex2html663"
49 HREF="node19.html">3. Using SDCC</A>
50 <B> Previous:</B> <A NAME="tex2html657"
51 HREF="node27.html">3.8 Critical Functions</A>
52   <B> <A NAME="tex2html665"
53 HREF="node1.html">Contents</A></B>
54   <B> <A NAME="tex2html667"
55 HREF="node61.html">Index</A></B>
58 <!--End of Navigation Panel-->
60 <H2><A NAME="SECTION00049000000000000000">
61 3.9 Naked Functions</A>
65 A special keyword may be associated with a function declaring it as
66 <I>_naked.</I> The <I>_naked</I> function modifier attribute prevents
67 the compiler from generating prologue and epilogue code for that function.
68 This means that the user is entirely responsible for such things as
69 saving any registers that may need to be preserved, selecting the
70 proper register bank, generating the <I>return</I> instruction at
71 the end, etc. Practically, this means that the contents of the function
72 must be written in inline assembler. This is particularly useful for
73 interrupt functions, which can have a large (and often unnecessary)
74 prologue/epilogue. For example, compare the code generated by these
79 <TT>data unsigned char counter;</TT>
81 <TT>void simpleInterrupt(void) interrupt 1</TT>
85 <TT> counter++;</TT>
90 <TT>void nakedInterrupt(void) interrupt 2 _naked</TT>
94 <TT> _asm</TT>
96 <TT> inc _counter</TT>
98 <TT> reti ; MUST explicitly include ret in _naked
101 <TT> _endasm;</TT>
107 For an 8051 target, the generated simpleInterrupt looks like:
111 <TT>_simpleIterrupt:</TT>
113 <TT> push acc</TT>
115 <TT> push b</TT>
117 <TT> push dpl</TT>
119 <TT> push dph</TT>
121 <TT> push psw</TT>
123 <TT> mov psw,#0x00</TT>
125 <TT> inc _counter</TT>
127 <TT> pop psw</TT>
129 <TT> pop dph</TT>
131 <TT> pop dpl</TT>
133 <TT> pop b</TT>
135 <TT> pop acc</TT>
137 <TT> reti</TT>
141 whereas nakedInterrupt looks like:
145 <TT>_nakedInterrupt:</TT>
147 <TT> inc _counter</TT>
149 <TT> reti ; MUST explicitly include ret(i) in _naked
154 While there is nothing preventing you from writing C code inside a
155 _naked function, there are many ways to shoot yourself in the foot
156 doing this, and is is recommended that you stick to inline assembler.
160 <!--Navigation Panel-->
161 <A NAME="tex2html668"
163 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
164 <A NAME="tex2html662"
166 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
167 <A NAME="tex2html656"
169 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
170 <A NAME="tex2html664"
172 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
173 <A NAME="tex2html666"
175 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
177 <B> Next:</B> <A NAME="tex2html669"
178 HREF="node29.html">3.10 Functions using private</A>
179 <B> Up:</B> <A NAME="tex2html663"
180 HREF="node19.html">3. Using SDCC</A>
181 <B> Previous:</B> <A NAME="tex2html657"
182 HREF="node27.html">3.8 Critical Functions</A>
183   <B> <A NAME="tex2html665"
184 HREF="node1.html">Contents</A></B>
185   <B> <A NAME="tex2html667"
186 HREF="node61.html">Index</A></B>
187 <!--End of Navigation Panel-->
190 <BR><I>2001-07-13</I>