Re: Microchip Introduces First 16-bit Microcontroller Product Line - the PIC24



On Sunday, in article
<43517dee$0$6773$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxx>
usenet@xxxxxxxxxxxxx "Andreas Schwarz" wrote:
>Chris Hills schrieb:
>> In article <43515ad8$0$6777$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxx>,
>> Andreas Schwarz <usenet@xxxxxxxxxxxxx> writes
>>>Ian Bell schrieb:
>>>>Andreas Schwarz wrote:
>>>>>Printf was only an example, the same applies to strcmp, puts, and many
>>>>>more, not to mention your own functions that operate on constant arrays.
>>>>>And besides, I don't think there's anything wrong with using printf on 8
>>>>>bit controllers. It makes serial debugging, LCD usage and things like
>>>>>that much more comfortable, and the additional 2-3 kB scarcely matter.
>>>>
>>>>LOL, that 2-3K makes a huge difference in products with 16K ROM or less and
>>>>there are very many of those.
>>>
>>>Optimization (writing a specialized function instead of using one from
>>>the library is nothing but optimization) is done when necessary, and no
>>>sooner. If your program with printf & Co. is 14k large and you target a
>>>16k microcontroller, replacing standard functions with specialized code
>>>will gain you absolutely nothing, but takes time, is error-prone, makes
>>>your code larger and hurts maintainability.
>>
>> This is absolute rubbish. A simple function to put a character or two
>> out to a serial line will only be a few bytes long.
> >
>> As printf has to use this functionality to address the hardware, and you
>> may want to re-direct printf, it is often made available in source form
>> in the library. All you have to do is get the routine. Typically it is
>> only 4-5 lines of C.
>
>Appearantly we have a misunderstanding here. With printf I do not mean a
>put-everything-on-stdout-C89-printf. Most libraries have a printf
>variant that takes a function pointer argument for a putc function, or a
>seperate function to set the printf target. Obviously you have to write
>this one yourself.

Creating a simple putc or put_string is easy.

>The point I was trying to make is that it is useless to assemble a LCD
>output by hand (formatting numbers, concatenating strings, padding with
>spaces) when there is a function like printf that can do it all much
>easiert, but may take a bit more space.

Creating a custom printf is MUCH better than using a library function
many applications do not need

Floats
scientific of exponential notation
pointer printing
long modifiers
escape characters (form feed, line feed, bell)

Mnay only need single character or formatted strings with a byte or short
(signed/unsigned printing).

To create a custom printf is relatively easy and I have used a few, created
and expanded over time to have conditionally compilation for support required
(binary, octal, decimal, hex, pointer). Simple formatting for single
characters or strings as standard. Some of the conditional assembly for
16bit ranging from 400 bytes to 1000 bytes, depending on the target being
developed. Hence code reuse just like using a library, with known overhead.

--
Paul Carpenter | paul@xxxxxxxxxxxxxxxxxxxxxxxxxxx
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.gnuh8.org.uk/> GNU H8 & mailing list info
<http://www.badweb.org.uk/> For those web sites you hate

.



Relevant Pages

  • Re: Microchip Introduces First 16-bit Microcontroller Product Line - the PIC24
    ... >>>Optimization (writing a specialized function instead of using one from ... >>>the library is nothing but optimization) is done when necessary, ... replacing standard functions with specialized code ... >> As printf has to use this functionality to address the hardware, ...
    (comp.arch.embedded)
  • Re: Bit twiddling
    ... I don't think it's too bad but an obvious optimization would be to ... >> print that string. ... Reducing the amount of calls (especially to big ones, like printf) is, ... This is better than the OPs printf function, ...
    (comp.lang.c)
  • Re: x86 Stack Confusion
    ... > To cheat in benchmarks that report the size of a "hello world" ... I think it is part of a general optimization of many ... No, if I actually *use* the return value of printf, then it does call ...
    (comp.lang.c)
  • Re: printf resisting to be used
    ... This is the same type that main has in a haskell program. ... you can eliminate the coercion ... to Float in the printf argument by making the type of interest ... represent the action of printing the strings, ...
    (comp.lang.functional)
  • Re: A Use of Static Typing
    ... which dynamic typing or type inference would allow. ... myprintf s = format s ... instance Printf ) where ... *obviously* does not accept strings, no matter what type system you are ...
    (comp.lang.misc)