Hello ! I have a problem which I can't resolve. I wrote program for 89C2051 for one of my friend in Basom Basic compiler (http://www.mcselec.com). Compiled code was about 1945 bytes. Since I prefer C, I transalte Bascom basic to C. But when I compile, generated code was 2313. I try to change optimization parameters, but generated code never go below 2313. Even bigger. Where am I wrong ? Is it possible that stupid Basic make smaller code tne best C compiler ? Then I find out that this code: while (1) { printf ("Hello World\n"); } generate fully 1093 bytes (!) for Atmel 89C2051. 1093 bytes???? Three lines? Same program in Bascom generate only 154 (!) bytes. When I remove all "printf" from my C code, generated code was arond 2200 byte. But, with same action in Basic code (remove all "print") 1340 bytes long code. Exactly same program in Keil C and Bascom basic generate 860 byte smaller code ! I don't belive this. Do I have to program in (stupid) Basic if I want smaller code ? I still belive I did mistake somewhere, so I need help. I will send both C and basic code for interested people. With best regards !
Erik, "but you come across as a "if it is too slow buy a faster (more expensive) processor, do not try to streamline the code, it may make it not proper" person" Not at all. Most of the 8051 stuff I work on is battery powered. Power consumption is of paramount importance - we use very low clock speeds and keep the CPU in idle mode >95% of the time. Maximum code space is 16k. Some aspects of data acquisition and output require very accurate timing. I spend a considerable amount of time making code as efficient as possible both in terms of speed and size. I don't use an RTOS - but I wouldn't hesitate to do so if it were beneficial to the project and feasible in terms of size and speed. I don't use C++ - but again I would readily do so given the above provisos. The constraints of the operating environment mean that we have to use a microcontroller rather than a microprocessor. The software needs to do a lot of complex floating point maths and give formatted output via the serial port. It achieves all this in a timely and efficient manner using printf() and the Keil floating point library. The microcontroller turns out to be perfectly suitable for a job that you seem to think is only suited to a microprocessor. My point is really this: If tools are available that are beneficial to the project then use them. Don't rule things out merely because you've decided at some time that they are not appropriate. There is no absolute divide between controllers and processors in much the same way that there is no absolute divide between what is and is not suitable for use on each device. Stefan