next up previous contents index
Next: 4.4 Interfacing with Assembly Up: 4. SDCC Technical Data Previous: 4.2 Pragmas   Contents   Index

4.3 <pending: this is messy and incomplete> Library Routines

The following library routines are provided for your convenience.

stdio.h - Contains the following functions printf & sprintf these routines are developed by Martijn van Balen <balen@natlab.research.philips.com>.

%[flags][width][b|B|l|L]type

           flags: -        left justify output in specified field width
                 +        prefix output with +/- sign if output is signed type
                 space    prefix output with a blank if it's a signed positive value
          width:          specifies minimum number of characters outputted for numbers
                          or strings.
                          - For numbers, spaces are added on the left when needed.
                            If width starts with a zero character, zeroes and used
                            instead of spaces.
                          - For strings, spaces are are added on the left or right (when
                            flag '-' is used) when needed.
                         
          b/B:            byte argument (used by d, u, o, x, X)
          l/L:            long argument (used by d, u, o, x, X)
          type:  d        decimal number
                 u        unsigned decimal number
                 o        unsigned octal number
                 x        unsigned hexadecimal number (0-9, a-f)
                 X        unsigned hexadecimal number (0-9, A-F)
                 c        character
                 s        string (generic pointer)
                 p        generic pointer (I:data/idata, C:code, X:xdata, P:paged)
                 f        float (still to be implemented)

Also contains a very simple version of printf (printf_small). This simplified version of printf supports only the following formats.

format     output type     argument-type
%d         decimal       short/int
%ld        decimal       long
%hd        decimal       char
%x        hexadecimal    short/int
%lx       hexadecimal    long
%hx       hexadecimal    char
%o         octal         short/int
%lo        octal         long
%ho        octal         char
%c        character      char
%s        character     _generic pointer

The routine is very stack intesive, -stack-after-data parameter should be used when using this routine, the routine also takes about 1K of code space. It also expects an external function named putchar(char) to be present (this can be changed). When using the %s format the string / pointer should be cast to a generic pointer. eg.

printf_small(``my str %s, my int %d\n'',(char _generic *)mystr,myint);

All library routines are compiled as -model-small, they are all non-reentrant, if you plan to use the large model or want to make these routines reentrant, then they will have to be recompiled with the appropriate compiler option.

Have not had time to do the more involved routines like printf, will get to them shortly.


next up previous contents index
Next: 4.4 Interfacing with Assembly Up: 4. SDCC Technical Data Previous: 4.2 Pragmas   Contents   Index
Johan Knol
2001-07-13