/******************************************************************/
/** **/
/** Major features. These determine what capabilities your **/
-/** comiled printf_fast will have. **/
+/** compiled printf_fast will have. **/
/** **/
/******************************************************************/
// Include support for 32 bit base 10 integers (%ld and %lu). Without
// this, you won't be able to print 32 bit integers as base 10. They
-// will appear in hexidecimal.
+// will appear in hexadecimal.
#define LONG
// Include support for floating point numbers (%f). Don't forget to
/* extern void putchar(char ); */
+// Warning: using static/global variables makes these functions NON-reentrant!
+// reentrant keyword is only used for parameter passing method
static bit long_flag, short_flag, print_zero_flag, negative_flag;
#ifdef FIELD_WIDTH
static bit field_width_flag;
+static bit leading_zero_flag;
static data unsigned char field_width;
#endif
void PRINTF_FAST(code char *fmt, ...) reentrant
{
- fmt; /* supress unreferenced variable warning */
+ fmt; /* suppress unreferenced variable warning */
_asm
clr _negative_flag
#ifdef FIELD_WIDTH
clr _field_width_flag
+ clr _leading_zero_flag
mov r1, #_field_width
mov @r1, #0
#endif
jnc printf_nondigit2
#ifdef FIELD_WIDTH
printf_digit:
+ jnz printf_digit_2
+ cjne a, _field_width, printf_digit_2
+ setb _leading_zero_flag
+printf_digit_2:
setb _field_width_flag
mov r2, a
mov a, @r1
#ifdef FIELD_WIDTH
jnb _field_width_flag, printf_str_loop
+ clr _leading_zero_flag // never leading zeros for strings
push dpl
push dph
printf_str_fw_loop:
printf_space_loop:
//mov a, #' '
mov a, #32
+ jnb _leading_zero_flag, printf_space_output
+ //mov a, #'0'
+ mov a, #48
+printf_space_output:
lcall printf_putchar
dec _field_width
printf_space: