Reshaped doc's
[fw/sdcc] / doc / sdccman.html / node41.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>4.3 &lt;pending: this is messy and incomplete&gt; Library Routines</TITLE>
11 <META NAME="description" CONTENT="4.3 &lt;pending: this is messy and incomplete&gt; Library Routines">
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="next" HREF="node42.html">
23 <LINK REL="previous" HREF="node40.html">
24 <LINK REL="up" HREF="node38.html">
25 <LINK REL="next" HREF="node42.html">
26 </HEAD>
27
28 <BODY >
29 <!--Navigation Panel-->
30 <A NAME="tex2html880"
31  HREF="node42.html">
32 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
33 <A NAME="tex2html874"
34  HREF="node38.html">
35 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
36 <A NAME="tex2html868"
37  HREF="node40.html">
38 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
39 <A NAME="tex2html876"
40  HREF="node1.html">
41 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
42 <A NAME="tex2html878"
43  HREF="node61.html">
44 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
45 <BR>
46 <B> Next:</B> <A NAME="tex2html881"
47  HREF="node42.html">4.4 Interfacing with Assembly</A>
48 <B> Up:</B> <A NAME="tex2html875"
49  HREF="node38.html">4. SDCC Technical Data</A>
50 <B> Previous:</B> <A NAME="tex2html869"
51  HREF="node40.html">4.2 Pragmas</A>
52  &nbsp <B>  <A NAME="tex2html877"
53  HREF="node1.html">Contents</A></B> 
54  &nbsp <B>  <A NAME="tex2html879"
55  HREF="node61.html">Index</A></B> 
56 <BR>
57 <BR>
58 <!--End of Navigation Panel-->
59
60 <H2><A NAME="SECTION00053000000000000000">
61 4.3 <I>&lt;pending: this is messy and incomplete&gt;</I> Library Routines</A>
62 </H2>
63
64 <P>
65 The following library routines are provided for your convenience.
66
67 <P>
68 stdio.h - Contains the following functions printf &amp; sprintf these
69 routines are developed by Martijn van Balen &lt;balen@natlab.research.philips.com&gt;. 
70
71 <P>
72  
73 %[flags][width][b|B|l|L]type
74
75 <P>
76  
77 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flags: -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; left justify output in
78 specified field width 
79 <BR>
80 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prefix output with
81 +/- sign if output is signed type 
82 <BR>
83 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; space&nbsp;&nbsp;&nbsp; prefix output with a
84 blank if it's a signed positive value 
85 <BR>
86 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; specifies minimum number
87 of characters outputted for numbers 
88 <BR>
89 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or strings. 
90 <BR>
91 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - For numbers,
92 spaces are added on the left when needed. 
93 <BR>
94 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If width starts
95 with a zero character, zeroes and used 
96 <BR>
97 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instead of
98 spaces. 
99 <BR>
100 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - For strings,
101 spaces are are added on the left or right (when 
102 <BR>
103 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag '-' is
104 used) when needed. 
105 <BR>
106 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
107 <BR>
108 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b/B:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte argument (used
109 by d, u, o, x, X) 
110 <BR>
111 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l/L:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long argument (used
112 by d, u, o, x, X)
113 <BR>
114 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type:&nbsp; d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decimal number 
115 <BR>
116 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; u&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned decimal
117 number 
118 <BR>
119 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned octal number
120
121 <BR>
122 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned hexadecimal
123 number (0-9, a-f) 
124 <BR>
125 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned hexadecimal
126 number (0-9, A-F) 
127 <BR>
128 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; character 
129 <BR>
130 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string (generic pointer)
131
132 <BR>
133 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generic pointer (I:data/idata,
134 C:code, X:xdata, P:paged) 
135 <BR>
136 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float (still to be
137 implemented)
138
139 <P>
140 Also contains a very simple version of printf (printf_small). This
141 simplified version of printf supports only the following formats.
142
143 <P>
144 format&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output&nbsp;type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;argument-type 
145 <BR>
146 %d &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decimal &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; short/int 
147 <BR>
148 %ld&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decimal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long 
149 <BR>
150 %hd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decimal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char 
151 <BR>
152 %x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexadecimal&nbsp;&nbsp;&nbsp;&nbsp;short/int 
153 <BR>
154 %lx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexadecimal&nbsp;&nbsp;&nbsp;&nbsp;long 
155 <BR>
156 %hx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexadecimal&nbsp;&nbsp;&nbsp;&nbsp;char 
157 <BR>
158 %o&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;short/int 
159 <BR>
160 %lo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long 
161 <BR>
162 %ho&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char 
163 <BR>
164 %c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char 
165 <BR>
166 %s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_generic pointer
167
168 <P>
169 The routine is very stack intesive, -stack-after-data parameter should
170 be used when using this routine, the routine also takes about 1K of
171 code space. It also expects an external function named putchar(char)
172 to be present (this can be changed). When using the %s format the
173 string / pointer should be cast to a generic pointer. eg.
174
175 <P>
176 printf_small(``my str %s, my int %d&#92;n'',(char
177 _generic *)mystr,myint);
178
179 <P>
180
181 <UL>
182 <LI>stdarg.h - contains definition for the following macros to be used
183 for variable parameter list, note that a function can have a variable
184 parameter list if and only if it is 'reentrant'
185
186 <P>
187 va_list, va_start, va_arg, va_end.
188
189 <P>
190  </LI>
191 <LI>setjmp.h - contains defintion for ANSI setjmp &amp; longjmp routines.
192 Note in this case setjmp &amp; longjmp can be used between functions
193 executing within the same register bank, if long jmp is executed from
194 a function that is using a different register bank from the function
195 issuing the setjmp function, the results may be unpredictable. The
196 jump buffer requires 3 bytes of data (the stack pointer &amp; a 16 byte
197 return address), and can be placed in any address space.</LI>
198 <LI>stdlib.h - contains the following functions.
199
200 <P>
201 atoi, atol.
202
203 <P>
204  </LI>
205 <LI>string.h - contains the following functions.
206
207 <P>
208 strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr,
209 strspn, strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp,
210 memset.
211
212 <P>
213  </LI>
214 <LI>ctype.h - contains the following routines.
215
216 <P>
217 iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
218 isxdigit, isalnum, isalpha.
219
220 <P>
221  </LI>
222 <LI>malloc.h - The malloc routines are developed by Dmitry S. Obukhov
223 (dso@usa.net). These routines will allocate memory from the external
224 ram. Here is a description on how to use them (as described by the
225 author).
226
227 <P>
228  
229 //Example: 
230 <BR>
231 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; #define DYNAMIC_MEMORY_SIZE 0x2000 
232 <BR>
233 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; ..... 
234 <BR>
235 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
236
237 <BR>
238 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; unsigned char xdata * current_buffer; 
239 <BR>
240 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; ..... 
241 <BR>
242 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; void main(void) 
243 <BR>
244 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; { 
245 <BR>
246 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... 
247 <BR>
248 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
249
250 <BR>
251 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Now it's possible to use malloc. 
252 <BR>
253 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... 
254 <BR>
255 &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current_buffer = malloc(0x100); 
256 <BR>
257 &nbsp;&nbsp;&nbsp;&nbsp; //
258
259 <P>
260  </LI>
261 <LI>serial.h - Serial IO routines are also developed by Dmitry S. Obukhov
262 (dso@usa.net). These routines are interrupt driven with a 256 byte
263 circular buffer, they also expect external ram to be present. Please
264 see documentation in file SDCCDIR/sdcc51lib/serial.c. Note the header
265 file ``serial.h'' MUST be included in the file containing the
266 'main' function.</LI>
267 <LI>ser.h - Alternate serial routine provided by Wolfgang Esslinger &lt;wolfgang@WiredMinds.com&gt;
268 these routines are more compact and faster. Please see documentation
269 in file SDCCDIR/sdcc51lib/ser.c</LI>
270 <LI>ser_ir.h - Another alternate set of serial routines provided by Josef
271 Wolf &lt;jw@raven.inka.de&gt;, these routines do not use the external ram.</LI>
272 <LI>reg51.h - contains register definitions for a standard 8051</LI>
273 <LI>float.h - contains min, max and other floating point related stuff.</LI>
274 </UL>
275 All library routines are compiled as -model-small, they are all non-reentrant,
276 if you plan to use the large model or want to make these routines
277 reentrant, then they will have to be recompiled with the appropriate
278 compiler option.
279
280 <P>
281 Have not had time to do the more involved routines like printf, will
282 get to them shortly.
283
284 <P>
285 <HR>
286 <!--Navigation Panel-->
287 <A NAME="tex2html880"
288  HREF="node42.html">
289 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
290 <A NAME="tex2html874"
291  HREF="node38.html">
292 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
293 <A NAME="tex2html868"
294  HREF="node40.html">
295 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
296 <A NAME="tex2html876"
297  HREF="node1.html">
298 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
299 <A NAME="tex2html878"
300  HREF="node61.html">
301 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
302 <BR>
303 <B> Next:</B> <A NAME="tex2html881"
304  HREF="node42.html">4.4 Interfacing with Assembly</A>
305 <B> Up:</B> <A NAME="tex2html875"
306  HREF="node38.html">4. SDCC Technical Data</A>
307 <B> Previous:</B> <A NAME="tex2html869"
308  HREF="node40.html">4.2 Pragmas</A>
309  &nbsp <B>  <A NAME="tex2html877"
310  HREF="node1.html">Contents</A></B> 
311  &nbsp <B>  <A NAME="tex2html879"
312  HREF="node61.html">Index</A></B> 
313 <!--End of Navigation Panel-->
314 <ADDRESS>
315 <I>Johan Knol</I>
316 <BR><I>2001-07-13</I>
317 </ADDRESS>
318 </BODY>
319 </HTML>