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);
va_list, va_start, va_arg, va_end.
atoi, atol.
strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn, strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.
iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace, isxdigit, isalnum, isalpha.
//Example:
// #define DYNAMIC_MEMORY_SIZE 0x2000
// .....
// unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
// unsigned char xdata * current_buffer;
// .....
// void main(void)
// {
// ...
// init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
// //Now it's possible to use malloc.
// ...
// current_buffer = malloc(0x100);
//
Have not had time to do the more involved routines like printf, will get to them shortly.