> > > >The article is in Scott Edward's April 1996 "Stamp Applications" of Nuts & > >Volts. > > > >In it, Scott shows the section of code: > > > > again: > > b1 = b1 + 1 ; increment b1 > > toggle 0 ; toggle pin 0 > > goto again > > > >and then goes on to give the following performance results: > > > > BS1, 4 MHZ 479 Hz > > . > > : > > 16C84, compiled 4 MHZ 7215 Hz > > > > > >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 > > Yep this would be real nice. :) > > >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. I think the output would be more likely to be 100KHz. 5 instructions on and 5 instructions off. > > I checked our multi-target Basic compiler with PIC as target with your > code and got 50 KHz for the same loop. I just checked the MPC compiler and it generates the 5 instruction sequence first shown above. One of our other compilers surprised me with the following code sequence equivalent. movlw 0x01 ; Setup Pin to Toggle again xorwf PORTB ; toggle pin 0 goto again The missing increment was caused by a default non-volitile variable that was never again referenced in the program. Its value did not matter. True comparitive benchmarks are tough to write. Walter Banks