??? 07/15/09 13:50 Read: times |
#167343 - and that's exactly the problem Responding to: ???'s previous message |
Andy Neil said:
Richard Erlacher said:
... the KEIL tools [and, by implication, 'C' tools in general] ... produce 2K of binaries for just a few dozen lines of 'C'.
http://www.8052.com/forum/read/167214 You are always saying that nobody should be allowed to use 'C' without a thorough understanding of the underlying architecture - which is fair enough (although we may disagree on what level constitutes sufficiently "thorough"). That's not what I've said all along. What I have said, is that nobody who couldn't write his code in ASM should be permitted to write his code in 'C'. There's a difference, you know! As for the size, the problem is that, once one is using 'C', the tendency is to use its libraries and other conveniences without regard for impact on the size of the work product. But I think we should add another rule: "Nobody should be allowed to make wild statements about any language without a thorough understanding of that language & how it works"
You continually make wild statements like this which show that you have very little understanding of the 'C' language. Of course an incompetent programmer can abuse the language and generate grossly inflated programs; but that is the fault of the programmer - not the lanuage nor the tools. The problem lies in that managers don't know that the programmers they've hired are incompetent. The let 'em do what they want, and the result is that everything's written in HLL, resulting in an implicit requirement for an MCU that's four times as large and fast as actually needed, just to make the product work. Yes, there ARE people who wouldn't do that, but just look at the queries we see on 8052.COM. The vast majority of "newbies" think that, just because they can make "Hello World" appear on their PC, they can write code for everything in 'C'. Yes indeed, there ARE people who can "do it right." How many of them do you see on 8052.COM? Only a few, right? For example, here is a simple "blinky" example taken direct from Keil:
/* BLINKY.C - LED Flasher for the Keil MCBx51 Evaluation Board with 80C51 device*/ #include <REG51F.H> void wait (void) { /* wait function */ ; /* only to delay for LED flashes */ } void main (void) { unsigned int i; /* Delay var */ unsigned char j; /* LED var */ while (1) { /* Loop forever */ for (j=0x01; j< 0x80; j<<=1) { /* Blink LED 0, 1, 2, 3, 4, 5, 6 */ P1 = j; /* Output to LED Port */ for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */ wait (); /* call wait function */ } } for (j=0x80; j> 0x01; j>>=1) { /* Blink LED 6, 5, 4, 3, 2, 1 */ P1 = j; /* Output to LED Port */ for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */ wait (); /* call wait function */ } } } } And the result is: LINK MAP OF MODULE: BLINKY (BLINKY) TYPE BASE LENGTH RELOCATION SEGMENT NAME ----------------------------------------------------- * * * * * * * D A T A M E M O R Y * * * * * * * REG 0000H 0008H ABSOLUTE "REG BANK 0" IDATA 0008H 0001H UNIT ?STACK * * * * * * * C O D E M E M O R Y * * * * * * * CODE 0000H 0003H ABSOLUTE CODE 0003H 0042H UNIT ?PR?MAIN?BLINKY CODE 0045H 000CH UNIT ?C_C51STARTUP CODE 0051H 0001H UNIT ?PR?WAIT?BLINKY Program Size: data=9.0 xdata=0 code=82 LINK/LOCATE RUN COMPLETE. 0 WARNING(S), 0 ERROR(S) Nowhere near 2K, is it?! Conversely, here is a simple "hello, world" example - also taken direct from Keil: /*------------------------------------------------------------------------------ HELLO.C Copyright 1995-1999 Keil Software, Inc. ------------------------------------------------------------------------------*/ #include <REG52.H> /* special function register declarations */ /* for the intended 8051 derivative */ #include <stdio.h> /* prototype declarations for I/O functions */ #ifdef MONITOR51 /* Debugging with Monitor-51 needs */ char code reserve [3] _at_ 0x23; /* space for serial interrupt if */ #endif /* Stop Exection with Serial Intr. */ /* is enabled */ /*------------------------------------------------ The main C function. Program execution starts here after stack initialization. ------------------------------------------------*/ void main (void) { /*------------------------------------------------ Setup the serial port for 1200 baud at 16MHz. ------------------------------------------------*/ #ifndef MONITOR51 SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */ TR1 = 1; /* TR1: timer 1 run */ TI = 1; /* TI: set TI to send first char of UART */ #endif /*------------------------------------------------ Note that an embedded program never exits (because there is no operating system to return to). It must loop and execute forever. ------------------------------------------------*/ while (1) { P1 ^= 0x01; /* Toggle P1.0 each time we print */ printf ("Hello Worldn"); /* Print "Hello World" */ } } And the result is: LINK MAP OF MODULE: HELLO (HELLO) TYPE BASE LENGTH RELOCATION SEGMENT NAME ----------------------------------------------------- * * * * * * * D A T A M E M O R Y * * * * * * * REG 0000H 0008H ABSOLUTE "REG BANK 0" DATA 0008H 0014H UNIT _DATA_GROUP_ 001CH 0004H *** GAP *** BIT 0020H.0 0001H.1 UNIT _BIT_GROUP_ 0021H.1 0000H.7 *** GAP *** IDATA 0022H 0001H UNIT ?STACK * * * * * * * C O D E M E M O R Y * * * * * * * CODE 0000H 0003H ABSOLUTE CODE 0003H 035CH UNIT ?PR?PRINTF?PRINTF CODE 035FH 008EH UNIT ?C?LIB_CODE CODE 03EDH 0027H UNIT ?PR?PUTCHAR?PUTCHAR CODE 0414H 001BH UNIT ?PR?MAIN?HELLO CODE 042FH 000DH UNIT ?CO?HELLO CODE 043CH 000CH UNIT ?C_C51STARTUP Program Size: data=30.1 xdata=0 code=1096 LINK/LOCATE RUN COMPLETE. 0 WARNING(S), 0 ERROR(S) Now, of course, that's much closer to 2K - but why? Obviously, because the programmer has chosen to use printf - which is an extremely powerful and versatile library function. But, of course, this power & versatility doesn't come for free: Just the description of printf in the Keil manuals runs to over 2 pages - so it's actually quite impressive that they manage to cram all that functionality into only 1000 bytes! If the programmer were concerned about minimising code size, he would not use printf in the first place! The thing is, of course, having used printf once means that you can use it extensively throughout your program without incurring any further overhead! Does it surprise you that KEIL would provide an example that shows their product in a good light? If only ALL HLL programmers would realize that. RE |