At 10:53 AM 12/1/96 EST, you wrote: >>> I was really disappointed/shocked in the performance numbers Scott Edwards >>> quoted in the article; they were something like 1,000x slower than what I >>> would consider a "decent" compiler (I seem to remember that a hand-written >>> assembler could be as much as 1,400x better) for the speed the PIC was >>> running at. Now, it is 10-50x better than the STAMP, but it's really pretty >>> slow. >> >>Which Pic BASIC was he talking about? PBASIC from Parallax is an >>interpreter. The "compile" option merely copies the interpreter and the >>P-Code into a PIC. > >Sorry for taking so long to reply; I had to find the original article. > >It's the Micro Engineering Labs BASIC - for $100.00. > >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 Myke, you forgot that MEL' PBASIC compiler is Compiler from Basic Stamp Basic, not a PIC Basic compiler. To be compatible with BS1 the compiler uses internal 16 bit mathm b1 = b1 + 1 will result in 16 bit addition! TOGGLE instruction makes pin output and toggles state, those the compiler must access Bank 1 to access tristate control. and later toggle the port pin. so there are things todo in such simple code too :) >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 checked our multi-target Basic compiler with PIC as target with your code and got 50 KHz for the same loop. Well our compiler only supports byte vars. And does not make any optimising. >I guess I exaggerated a bit for the relative improvement - I was talking >about 1,000x when I should have said 30x. > >But, I think you can see that there is area for concern/improvement. Not >only in terms of speed, but also in terms of instruction space; what is the >PIC executing during this loop? see above, it is also translating pin number to bit mask. and resets watchdog at every basic instruction. >>There are also one or two true Pic BASIC compilers out there that produce >>native PIC code. >> >>The latter should be much faster than the former. > >According to the article, this Compiler is creating native code. Hm, I checked the native compiler and got 12.8 KHz for your loop. Maybe I did something wrong. antti -- Silicon Studio Ltd. -- http://www.sistudio.com