|
|
View previous topic :: View next topic |
Author |
Message |
none Guest
|
code size, putc() vs printf() |
Posted: Fri Mar 07, 2003 3:09 pm |
|
|
gents,
consider this example short snippet:
#use rs232(baud=9600,xmit=PIN_DEBUG_TX,rcv=PIN_DEBUG_RX,errors,stream=L
CD)
void lcd_putc(char c) {
fputc(c,LCD);
}
i have noticed some code size difference between the following:
lcd_putc("abcdef");
vs.
printf(lcd_putc,"abcdef");
i realize that the latter is required for more complex printing tasks (e.g. parameter/variable substitution). BUT, for this example, with a "constant" string passed, should these two lines result in the same number of instructions?
thanks and regards
___________________________
This message was ported from CCS's old forum
Original Post ID: 12465 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: code size, putc() vs printf() |
Posted: Fri Mar 07, 2003 6:09 pm |
|
|
:=i have noticed some code size difference between the following:
:=
:=lcd_putc("abcdef");
:=vs.
:=printf(lcd_putc,"abcdef");
:=
:=i realize that the latter is required for more complex printing tasks (e.g. parameter/variable substitution). BUT, for this example, with a "constant" string passed, should these two lines result in the same number of instructions?
-------------------------------------------------------
Use a different string for each test. If you use the
same string for each test, the compiler optimizes the
code, and generates only one set of "character fetch"
code. See the code below.
With the following code, the ROM usage is very nearly
the same. The compiler uses a different method to
determine the end of the strings -- for lcd_putc(),
it looks for a string terminator (0x00) but for printf(),
it counts up 6 chars. With PCM vs. 3.146 on a 16F877,
the difference in ROM usage is only 1 location, between
the two methods.
<PRE>
#include "c:\Program Files\Picc\Devices\16F877.h"
#fuses HS, NOWDT, NOPROTECT,PUT,BROWNOUT, NOLVP
#use Delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=LCD)
<BR>
void lcd_putc(char c)
{
fputc(c,LCD);
}
<BR>
//====================================================
<BR>
void main()
{
<BR>
lcd_putc("abcdef");
<BR>
printf(lcd_putc,"ABCDEF"); // This is a different string
<BR>
while(1);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12474 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|