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>4.3 <pending: this is messy and incomplete> Library Routines</TITLE>
11 <META NAME="description" CONTENT="4.3 <pending: this is messy and incomplete> Library Routines">
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="node42.html">
23 <LINK REL="previous" HREF="node40.html">
24 <LINK REL="up" HREF="node38.html">
25 <LINK REL="next" HREF="node42.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="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   <B> <A NAME="tex2html877"
53 HREF="node1.html">Contents</A></B>
54   <B> <A NAME="tex2html879"
55 HREF="node61.html">Index</A></B>
58 <!--End of Navigation Panel-->
60 <H2><A NAME="SECTION00053000000000000000">
61 4.3 <I><pending: this is messy and incomplete></I> Library Routines</A>
65 The following library routines are provided for your convenience.
68 stdio.h - Contains the following functions printf & sprintf these
69 routines are developed by Martijn van Balen <balen@natlab.research.philips.com>.
73 %[flags][width][b|B|l|L]type
77 flags: - left justify output in
80 + prefix output with
81 +/- sign if output is signed type
83 space prefix output with a
84 blank if it's a signed positive value
86 width: specifies minimum number
87 of characters outputted for numbers
89 or strings.
91 - For numbers,
92 spaces are added on the left when needed.
94 If width starts
95 with a zero character, zeroes and used
97 instead of
100 - For strings,
101 spaces are are added on the left or right (when
103 flag '-' is
106
108 b/B: byte argument (used
111 l/L: long argument (used
114 type: d decimal number
116 u unsigned decimal
119 o unsigned octal number
122 x unsigned hexadecimal
125 X unsigned hexadecimal
128 c character
130 s string (generic pointer)
133 p generic pointer (I:data/idata,
134 C:code, X:xdata, P:paged)
136 f float (still to be
140 Also contains a very simple version of printf (printf_small). This
141 simplified version of printf supports only the following formats.
144 format output type argument-type
146 %d decimal short/int
148 %ld decimal long
150 %hd decimal char
152 %x hexadecimal short/int
154 %lx hexadecimal long
156 %hx hexadecimal char
158 %o octal short/int
160 %lo octal long
162 %ho octal char
164 %c character char
166 %s character _generic pointer
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.
176 printf_small(``my str %s, my int %d\n'',(char
177 _generic *)mystr,myint);
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'
187 va_list, va_start, va_arg, va_end.
191 <LI>setjmp.h - contains defintion for ANSI setjmp & longjmp routines.
192 Note in this case setjmp & 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 & a 16 byte
197 return address), and can be placed in any address space.</LI>
198 <LI>stdlib.h - contains the following functions.
205 <LI>string.h - contains the following functions.
208 strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr,
209 strspn, strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp,
214 <LI>ctype.h - contains the following routines.
217 iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
218 isxdigit, isalnum, isalpha.
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
231 // #define DYNAMIC_MEMORY_SIZE 0x2000
233 // .....
235 // unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
238 // unsigned char xdata * current_buffer;
240 // .....
242 // void main(void)
244 // {
246 // ...
248 // init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
251 // //Now it's possible to use malloc.
253 // ...
255 // current_buffer = malloc(0x100);
257 //
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 <wolfgang@WiredMinds.com>
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 <jw@raven.inka.de>, 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>
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
281 Have not had time to do the more involved routines like printf, will
286 <!--Navigation Panel-->
287 <A NAME="tex2html880"
289 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
290 <A NAME="tex2html874"
292 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
293 <A NAME="tex2html868"
295 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
296 <A NAME="tex2html876"
298 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
299 <A NAME="tex2html878"
301 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
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   <B> <A NAME="tex2html877"
310 HREF="node1.html">Contents</A></B>
311   <B> <A NAME="tex2html879"
312 HREF="node61.html">Index</A></B>
313 <!--End of Navigation Panel-->
316 <BR><I>2001-07-13</I>