Interpreter or compiler?

RonCzap

Member
I know the PICAXE uses a bootstrap program to load programs from the program editor but I am unclear as to what happens next.

Does the program editor generate assembler instructions that are directly executed by the PIC or is the code in some other format where each instruction gets interpretted before being executed (e.g. the Basic Stamp "token" scenario)?

Does the bootstrap program basically just save the code in memory and then monitor the serin pin for attempts to load a new program?

Thanks,
Ron
 

Andrew Cowan

Senior Member
PICAXE is an interpreted language - so the bootloader interprets each instruction before executing it.

This means it's not nearly as fast as a compiled program on a PIC - but it's fast enough for most purposes.

A
 

RonCzap

Member
@Andrew,
Thanks for your prompt reply. I checked the PICAXE manuals and web site but could not find the answer.

I appreciate your help.
 

hippy

Ex-Staff (retired)
Interpreter or compiler?
It's a challenging question.

In the sense of "does the Programming Editor compile source code to native PICmicro instructions which are executed directly by the silicon ?"; no, it's not a compiler.

But, as the token code is the native instruction set for the PICAXE interpreter, the Programming Editor can be considered a compiler, just as Java and the like are considered when they convert source code to bytecode.

So, technically, it's not a question of "or" but a matter of "and".
 

mrburnette

Senior Member
My take on this is along the lines of a .NET program; the PICAXE is preloaded with numerous "library" routines and state-management routines. The PC "complier" does more than just tokenizes the PBASIC code, it essentially constructs a pre-digested and optimized set of library calls. Just as Hippy suggested, this is the function of a compiler in the sense that it is similar to JAVA, .NET, or even Visual Basic.

Were we compiling in pure PIC assembly, our libraries would be referenced and linked based upon an analysis of our code during the 1st compiler pass which would look externally to resolve library calls. However, depending on how granular the libraries are, some bloated code could still be loaded. With the PICAXE, all the libraries are pre-installed completely in the PICAXE, in my understanding, and so a small change in source program to include a new function simply set ups an internal call in the PICAXE with the necessary variables passed to the new routine referenced.

From experience, I find that developing with the PICAXE in PBASIC eliminates the need to keep library dependencies and such in my head! At my age, I need all of the extra neurons for daily use. Obviously, there is some "bloat" internal to the PICAXE, but for small runs of projects, this is not a really big deal since the PICAXE price structure is most reasonable. However, if I were planning on 1000+ distributions, I would opt to rework the PBASIC code in C or pure assembler for a native PIC... but, that is just me.

- Ray
 
Last edited:

westaust55

Moderator
My take on this is along the lines of a .NET program; the PICAXE is preloaded with numerous "library" routines and state-management routines. The PC "complier" does more than just tokenizes the PBASIC code, it essentially constructs a pre-digested and optimized set of library calls. Just as Hippy suggested, this is the function of a compiler in the sense that it is similar to JAVA, .NET, or even Visual Basic.
A couple of clarifications:
1. PBASIC is the name Parallax use for their version of BASIC as used for the BASIC Stamp microcontrollers.
Rev Ed sold/supported BASIC Stamps long ago and the Programming Editor still has support for the BASIC Stamp1.
However, while similar, by my understanding the Rev Ed version of BASIC is not referred to as PBASIC (for copyright reasons)

2. The PC "Compiler" as you call it (aka the PICAXE Programming Editor) basically does only tokenise the BASIC program form the listing we understand and virtually nothing more.
Each BASIC keyword is converted from a multi ASCII character string into a single multi-bit token (varies depending on PICAXE chip but always less than 8 bits). Variable names and constant values are likewise compressed. Then there are a few extra bits as flags.
It is then the function of the Interpreter in the PICAXE firmware to work through that tokenised code and call the required machine code subrotuines necessary to perform the task required by the BASIC keyword.

If you are interested, have a read at the information in post 9 here: http://www.picaxeforum.co.uk/showthread.php?17782-PICAXE-program-Size-Optimisations-and-Speed
The content of the attachment at post 9 is based on past work primarily by hippy and more recent extensive investigations by myself early this year (not all information is published for good reason) .
 

Dippy

Moderator
Many terms are blurred nowadays.
To my mind PICAXE BASIC is a tokeniser-compiler with a bootloader-interpreter and it's nearest comparison would be Stamp.
There will obviously be differences that I (nor anyone here except Rev-Ed) have much idea about, but one thing is for sure; PICAXE is miles better value than a Stamp.

But PICAXE BASIC isn't a 'true' compiler in the Microcontroller programming sense when compared to MPLAB/HiTech and similar.
And many compilers make the linking and building fairly invisible, so Compiling/Linking/Building/Loading on a true compiler is as simple as the PICAXE Programming Editor function. The PPE, however, does a pile of things for you so that you can get on with the actual function aspect rather than having to twiddle with your TRIS :)
Horses for Courses.

Obv for a real production run you would use other options, but that really isn't the target for this excellent educational, hobbyist product. Users of PICAXE are getting fantastic value for money.
Most Pro code writers don't write long ASM programmes anyway. Most will be purely C (or similar) and some will insert ASM routines for any specific sections.
These days we are quite spoilt for choice. Good innit ;)
(Qu1: How many times has this question been asked?
Qu2: Westy, is your PC attached to your bed? Do you ever sleep?)
 

RonCzap

Member
A couple of clarifications:
1. PBASIC is the name Parallax use for their version of BASIC as used for the BASIC Stamp microcontrollers.
Rev Ed sold/supported BASIC Stamps long ago and the Programming Editor still has support for the BASIC Stamp1.
However, while similar, by my understanding the Rev Ed version of BASIC is not referred to as PBASIC (for copyright reasons)

2. The PC "Compiler" as you call it (aka the PICAXE Programming Editor) basically does only tokenise the BASIC program form the listing we understand and virtually nothing more.

.......
westaust55,
Thanks - you pretty much confirmed my assumptions. I wondered though when I saw the "Convert Basic to Assembler" menu option.

I used to write MS DOS assembler programs where you compiled the source code into an object file and then linked it to produce an executable (com or exe), so I was trying to make sure I knew how the PICAXE editor works.

I was an IBM mainframe programmer for 22 years and then moved into VB6 and Visual Studio Web development for 7 years before I retired.

I have several Basic Stamps, Propellers, and Arduinos and, of course, they all work differently but I am certainly impressed by the PICAXE line (although it can be a little confusing as to what is supported on the various chips).

So far I have 20M2, 20X2 and 08M2 chips to explore...
 

mrburnette

Senior Member
A couple of clarifications:
...
2. The PC "Compiler" as you call it (aka the PICAXE Programming Editor) basically does only tokenise the BASIC program form the listing we understand and virtually nothing more.

If you are interested, have a read at the information in post 9 here: http://www.picaxeforum.co.uk/showthread.php?17782-PICAXE-program-Size-Optimisations-and-Speed...
Thanks for the link, I'm getting ready to educate myself. In retrospect it seems reasonable to limit the compile to a tokenized format and parse/interpret within the uC... it's not how I would have started out but but the popularity and stability of the platform is proof that the chosen path is appropriate.

- Ray
 
Top