1 /*-----------------------------------------------------------------
2 printfl.c - source file for reduced version of printf
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
24 2001060401: Improved by was@icb.snz.chel.su
25 -------------------------------------------------------------------------*/
28 /* following formats are supported :-
29 format output type argument-type
32 %hd decimal short/char
35 %hx hexadecimal short/char
39 %c character char/short
40 %s character _generic pointer
46 #include <reg51.h> // for the SP
49 static data volatile char ch;
50 static data char radix ;
51 static bit long_flag = 0;
52 static bit string_flag =0;
53 static bit short_flag = 0;
55 static char * data str ;
58 static void pval(void)
64 if (val < 0 && radix != 16)
69 else { sign = 0; lval = val;}
81 if(radix != 16) ch = (lval % radix) + '0';
82 else ch = "0123456789ABCDEF"[(unsigned short)lval & 0x0f];
83 _asm push _ch _endasm;
86 // This only looks more efficient, but isn't. see the .map
87 ch = (lval % radix) + '0';
89 _asm push _ch _endasm;
97 _asm push _ch _endasm;
101 _asm pop _ch _endasm;
106 void printf_small (char * fmt, ... ) reentrant
112 for (; *fmt ; fmt++ ) {
114 long_flag = string_flag = short_flag = 0;
145 str = va_arg(ap, char _generic *);
146 while (*str) putchar(*str++);
151 val = va_arg(ap,long);
154 val = va_arg(ap,short);
156 val = va_arg(ap,int);
159 else putchar((char)val);