Here is the code produced when I ran it thru the PicBasic compiler: Basic: again: b1 = b1 + 1 ; increment b1 toggle 0 ; toggle pin 0 goto again Compiler output in asm: _again movf _B1,W call R0@0W movlw 001h call add@0W movf R0,W movwf _B1 movlw 000h call toggle@ @GOTO _again Note the three subroutine calls ... not quite as tight as Myke's code. The first call loads R0 from W. Then the constant "1" is loaded into W, and a subroutine is called to do the addition. Then registers are mucked about with and the toggle subroutine is called. I'm no compiler expert, althought I did study the subject years ago, and wrote some compiler code as a fun project. Converting "b=b+1" into "increment b" is what is called peephole (or local) optimisation ... look at a single statement, and see if the code can't be tightened up. Obviously the MEL compiler is not doing this in what is probably the most obvious case of peephole optimization, since most computers have an increment/decrement instruction, and this contruct is so commonplace. It is same, therefore, to assume that the MEL compiler doesn't do any optimization. But for $99, perhaps one should not expect much. What is real interesting about the MEL compiler is that they provide the library in source form, and the compiler produces ASM out the back end. It would be possible (although a fair bit of work) for a person to optmize code manually, assuming one knew assembler. Of course, if one did, one would probably write in assembler from the beginning, wouldn't one! We must recognize what the MEL PicBasic compiler was meant to do .... provide a means to write code for a 16C84, in Basic. The code will be faster for two reasons ... it does not have to be interpreted, and more important, it does not have to be read from S-L-O-W serial EEPPROM. Hopefully, it will also be small, since the compiler only includes those library routines it needs, whereas the real BASIC interpreter has all the library code builtin. I'm sure the folks at MEL could produce a much better version of the compiler if there was an economic incentive to do so. Larry >---------- >From: myke predko[SMTP:myke@PASSPORT.CA] >Sent: Sunday, December 01, 1996 10:53 AM >To: Multiple recipients of list PICLIST >Subject: Re: Pic basic > (snip) >Now, my thought was that any decent compiler would produce the following >code: > >again > incf b1 ; increment b1 > movlw 0x01 ; toggle pin 0 > xorwf PORTB ; Assume pin 0 is in PORTB > goto again > >This can be improved to: > > movlw 0x01 ; Setup Pin to Toggle >again > incf b1 ; increment b1 > xorwf PORTB ; toggle pin 0 > goto again > >Although while I would expect this type of optimization for a workstation >compiler, I wouldn't think that it would be reasonable for a Hobbyist one. > >The first loop takes five instruction cycles to run (the second four) - five >instructions running at 4 Mhz (1 MHz Instruction cycle frequency) means that >the loop would run at 200 KHz. >(snip) >