I'm gonna start a small hobby project making use of a Zilog Z8 Encore microcontroller. It will drive an alphanumeric LCD display, control a relay, and handle inputs from a few switches/buttons as well as a single optical rotary encoder. Basically a glorified digital timer.
It has been awhile and my previous embedded experience has been with
32-bit processors with large 8mb flash chips.
Assuming I can write some tight C-code, 8K of flash should be plenty, right?
Thanks for the responses. I think it will be plenty too...just wanted to bounce it off others. Since the LCD is alphanumeric, I won't be blowing memory on fonts and such.
To answer the above comment, I don't plan on writing/designing the code before I get the development board and compiler. I am not at all concerned with RAM. I figure 8k of flash probably gives me 7000 instructions or so (1k used for initialized data and such). Maybe average each line of C-code as 4 instructions. This should give me roughly 1700 lines of C to work with. Plenty for logic...doing fixed point integer arithmetic could get messy.
I'll second that. I did a medium complexity Z8 Encore project this year and found that attempts to use libraries would result in little remaining space for my code. For example, I wound up coding a specialized version of scanf() rather than including the string library. I also spent some time optimizing a message parser to keep things tight. Nothing too heroic but certainly not the first cut, either.
--
========================================================================
Michael Kesti | "And like, one and one don't make
"Wim Ton" wrote in news:qJg9d.10208$BI5.7635 @fe2.news.blueyonder.co.uk:
Such measures also depend quite a bit on how you count lines and how the application is written. I once wrote a ~10K-15K line C application that worked out to slightly less than one byte per line of code. That was a bit of an anomoly though.
--
Walter Mallory walter.mallory@mbda-us.com
Reach, Connect, Celebrate, Grow, Serve
Those are unrealistic ratios. The following code, with gcc on the x86, generates 76 bytes with -O3 optimization, 153 bytes without optimization. There are 4 lines generating code, 5 if you include initialization, 8 if you also insist on one statement per line. Most instructions are 2 bytes.
With the Metrowerks 68K compiler, the example generated 78 bytes of code without optimization and 70 bytes with the highest level of optimization. As on the x86, most of the instructions generated were two bytes long (the minimum on the 68K). I wonder what the
2:1 difference says about optimization and the x86 instruction set?
Incidentally, rewriting the example the way I would normally write it----without mixing boolean and character expressions:
#include int strncmp(const char *s1, const char *s2, size_t n) { unsigned const char *c1 = s1, *c2 = s2; while ((*c1 != 0) && (*c1 == *c2) && (n > 0)) { c1++; c2++; n--; } if (n > 0) { if (*c1 > *c2) rval = 1; // did I get the sense right?? if (*c1 < *c2) rval = -1; } else rval = 0;
return rval; } /* strncmp untested */
results in a code length of 56 bytes optimized and 60 bytes unoptimized.
I guess that means that there really is a penalty for mixing up your boolean expressions with character and arithmetic comparisons! ;-)
Incidentally, the Codewarrior compiler didn't have to use any stack space for the temporary rval. The code used only the A0, A1, D0, D1, and D2 registers---which apparently can be used without a save and restore. The result is returned in D0.
Here's the assembly listing----not a lot of apparent fat in this code.
int xstrncmp( const char *s1, const char *s2, size_t n){
I think you got the return condition wrong. The exit portion should be:
if (n = 0) rval = 0; else if (*c1 > *c2) rval = 1; else if (*c1 < *c2) rval = -1; else rval = 0;
to handle strings that are of unequal length and less than n long. I think this code will be slower on machines doing look ahead because of extra pipeline flushing. The actual loop should generate the same code either way.
--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
Pipelines and special branch prediction hardware make it really difficult to optimize code for many of the newer processors. That's one of the reasons it is more difficult now for even an assembly- language expert to beat out the C compilers. You are essentially matching your skills against those of the processor expert who wrote the code generator for the compiler. I might enter the contest with the 68K systems and (going back a bit) the 6809 or 6800, but I would never make that bet with the MSP 430 or the ARM 7 series.
As my test showed, the programmer's C style can make a significant difference in the code generates. Perhaps the best results are to be had if the programmer writes C like he was writing assembly for the PDP-11 (been there, done that!)
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.