From: bernhardheld Date: Sat, 8 Feb 2003 11:01:58 +0000 (+0000) Subject: * device/lib/printfl.c: fix a ds390 bug by making it portable X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=4107b33897ec0adbbab1e60b8ed569de5826b793;p=fw%2Fsdcc * device/lib/printfl.c: fix a ds390 bug by making it portable git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2222 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 239abfa1..302f0965 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2003-02-08 Bernhard Held * device/lib/_mulint.c: small fix for large/ds390 --int-long-reent resp. --stack-auto + * device/lib/printfl.c: fix a ds390 bug by making it portable 2003-02-05 Jesus Calvino-Fraga diff --git a/device/lib/printfl.c b/device/lib/printfl.c index 0754fb79..b863d7a5 100644 --- a/device/lib/printfl.c +++ b/device/lib/printfl.c @@ -20,7 +20,7 @@ In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! - + 2001060401: Improved by was@icb.snz.chel.su -------------------------------------------------------------------------*/ @@ -42,23 +42,37 @@ #include #include +#include #ifndef __ds390 /* just for the SP */ #include <8051.h> #endif -static data volatile char ch; static data char radix ; static bit long_flag = 0; static bit string_flag =0; static bit char_flag = 0; -static bit sign; static char * data str ; static data long val; +/* This great loop fails with the ds390 port (2003-01-13). + + At the beginning resp. end of the loop the compiler inserts a "push ar2" + resp. "pop ar2", which badly interfers with the push/pop in the source. + + Library functions should be rock solid and portable. There's an _ltoa in + the library, so let's use it and don't reinvent the wheel. + + Bernhard +*/ + +#if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE +static data volatile char ch; +static bit sign; + static void pval(void) { - char sp; + volatile char sp; unsigned long lval; sp = SP; @@ -78,18 +92,19 @@ static void pval(void) do { -#if 1 + +# if 1 if(radix != 16) ch = (lval % radix) + '0'; else ch = "0123456789ABCDEF"[(unsigned char)lval & 0x0f]; _asm push _ch _endasm; lval /= radix; -#else +# else // This only looks more efficient, but isn't. see the .map - ch = (lval % radix) + '0'; - if (ch>'9') ch+=7; - _asm push _ch _endasm; + ch = (lval % radix) + '0'; + if (ch>'9') ch+=7; + _asm push _ch _endasm; lval /= radix; -#endif +# endif } while (lval); @@ -103,6 +118,7 @@ static void pval(void) putchar(ch); } } +#endif void printf_small (char * fmt, ... ) reentrant { @@ -156,8 +172,21 @@ void printf_small (char * fmt, ... ) reentrant else val = va_arg(ap,int); +#if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE if (radix) pval(); - else putchar((char)val); +#else + if (radix) + { + static char data buffer[12], c; + + _ltoa (val, buffer, radix); + str = buffer; + while ((c = *str++) != '\0') + putchar (c); + } +#endif + else + putchar((char)val); } else putchar(*fmt);