William Chops Westfield wrote: > On Jun 26, 2004, at 5:11 PM, Gerhard Fiedler wrote: > > >> Before these changes C18/PIC18F encouraged the use of poor programming > >> practices because using global variables in access ram was so much > >> more > >> efficient than passing arguments and using local variables. > > > > Isn't that the case with pretty much all 8bit micros? > > Well, no. At the recent AVR seminar, they specifically reccomended > against global variables. Seems that the compiler tries to put global > variables in RAM, while local variables get allocated in registers. > It also seems that the avr has enough pointer registers and addressing > mores that it is more efficient to access fields of a structure than > the equivilent global variables, since accessing global ram can take a > 4 byte instruction (to hold the whole 16+ bit ram address), while > offsets from a pointer register are two-byte instructions. > > While interesting, these suggestions made me somewhat unimpressed with > the optimization capabilities of whatever compiler they were using. > Any compiler ought to be smart enough to put all the global variables > into registers (if they fit.) (to be fair, it wasn't clear whether > they meant this mainly for the cases where not all the variables fit in > registers; using local variables makes it possibles (or at least a lot > easier) to determine when you can reuse a location because it's not > used anymore...) Any good compiler ought to be able to reference > global memory as offsets to a global heap pointer if the improvement in > memory utilization is that significant... (although I don't know how > hard that would be, really.) > > BillW Exactly! And with regard to how difficult it would be, answer: not very hard. Regards Sergio Masci http://www.xcprod.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.