Hello there,
I'm new to hardware-related programming and currently having my first experiences with MSP430G2553. I'm using CCS 5.3 and building an application which is printing stuff to a LCD. For this purpose, I found oPossum's tiny printf here: http://forum.43oh.com/topic/1289-tiny-printf-c-version/
But because I need also to print floating point values, I added some lines to this routine. Showing only the added lines of code:
void printf(char *format, ...)
{
// ....
volatile double f;
// ....
case 'f':
//format++;
i = (*format++)-48; // numer of fractional digits
f = va_arg(a, double);
if(f < 0 ) f = -f, putc('-');
xtoa((unsigned long)f, dv); // integral part
putc('.');
xtoa((unsigned long) ((f-((int) f)) * *(dv + (9-i))), dv+5); // fractional part
break;
case 0: return;
default: goto bad_fmt;
}
} else
bad_fmt: putc(c);
}
va_end(a);
}
With that, I am able to do something like printf("%f2", 3.1415f) to have two fractional digits.
My total code size in Flash according to the .map file with the original printf-Function was 0x13A2 bytes. With this added lines (case 'f'), it's 0x24F4. That means, it's almost double size! Wow.Mainly the last call of xtoa is responsible for this.
Why? What is happening here, what is beeing added to my code? And just for interest: If I change the mult in last call of xtoa to an a plus, it's 1396 byte less.
How can I implement this function more efficient?
Thank you!