David Harper said:
[email protected] (Colubris) wrote in message
So those compilers allow standard PICS (from Microchip Technologies)
to be programed in BASIC? How much slower is a PIC program in BASIC
than assembly?
Thanks!
Dave
This depends on three things (1) the person doing the programming in
assembler,
(2) the BASIC compiler and (3) the complexity of the problem.
A good BASIC compiler WILL produce code that is within 10-20% of that
produced
by an experienced assembler programmer. If the assembler programmer is not
very
experienced then a good BASIC compiler WILL produce code that is MUCH more
efficient.
As the complexity of a problem increases so too does the ability of a good
compiler to outperform the assembler programmer. The compiler is a tool that
enables the computer to automatically perform hundreds of thousands of tests
on
your code. A good compiler will search for optimisations that an experienced
assembler programmer would find laborious and a non-experienced assembler
programmer would not even know about. Most importantly, the compiler can do
all
this work each and every time you make a change to your program. An
assembler
programmer would typically only look at a small part of the program when he
changes it.
Some compilers convert BASIC source code into a special internal form that
requires an interpreter to run. This internal code is downloaded into the
PIC
and then processed by an interpreter that is running on the PIC. Each
instruction in the BASIC program is effectively executed by the interpreter.
If
the instruction is executed 10 times in the BASIC source then it will be
executed 10 times by the interpreter.
Some compilers convert BASIC source code into machine code which is the same
stuff that assemblers produce. A mediocre compiler will generate several
machine
code instructions for each BASIC instruction. A good compiler will combine
multiple BASIC instructions and generate fewer machine code instructions.
Programs executed by an interpreter WILL run much (several hundred times)
slower
than an optimised machine code executable produced by a good compiler that
produces machine code.
The XCSB compiler will convert the following to just 6 machine code
instructions:
proc inline set_bit(ubyte *addr, ubyte id)
*addr = *addr | (1 << id)
endproc
proc inline clear_bit(ubyte *addr, ubyte id)
*addr = *addr & ~(1 << id)
endproc
proc inline ubyte test_bit(ubyte *addr, ubyte id)
return (*addr & (1 << id) != 0)
endproc
proc main()
ubyte a, b
if (test_bit(&a, 1) then
set_bit(&b, 2)
else
clear_bit(&b, 2)
endif
endproc
A 20MHz 16F876 can execute (aprox) 5,000,000 machine code instructions per
second.
Regards
Sergio Masci
http://www.xcprod.com/titan/XCSB - optimising PIC compiler
FREE for personal non-commercial use