PE6 Program Editor and Assembly Code Generation

Sten Martin

New Member
I want to test the speed of PE6 generated Assembly Code on PIC. Will it work with a PIC18F25K20?

This is how I understand it.

To be able to create Assembly Code for PIC18F25K20 (PICAXE 28X2) I need the BAS 800 PIC Programmer, nothing else will work?

The program has to developed in Basic on the PICAXE 28X2. When the program is finished and simulated through the Program Editor (PE6) it can be converted to assembly with help of the Program Editor and the assembly program can be uploaded to the PIC chip for much faster execution - is that right?

To Program the PIC micro-controller in assembler code with a BAS 800 PIC programmer we need the following:

Start buying PICAXEs for 'development' and then use the much cheaper PICs for finished projects - (if you need the extra speed).

The Program Editor (PE6)software allows BASIC programs to be automatically converted into assembler code.

The conversion process has specifically been designed to be ‘sequential’ so that each BASIC command becomes a recognizable ‘block’ of assembler code to make this process much easier to understand.

To program micro controllers with an assembler code program you require a BAS 800 PIC Programmer, nothing else will work?

The BASIC to Assembler conversion function will also not operate unless the BAS 800 PIC programmer is attached to the Window based PC with the PE6 Editor running.

You also need the USB cable AXE027 connected and the USB driver installed.

Is that all?
 

srnet

Senior Member
There were plans to introduce a new assembler option for PE6, but no details released that I have seen.

A 28X2 is a 18F25K22.
 

nick12ab

Senior Member
To program micro controllers with an assembler code program you require a BAS 800 PIC Programmer, nothing else will work?

The BASIC to Assembler conversion function will also not operate unless the BAS 800 PIC programmer is attached to the Window based PC with the PE6 Editor running.
That was true for previous versions of PICAXE Programming Editor. However the BASIC-to-Assembler function in Programming Editor was/is very basic and only supports a limited selection of commands. Apparently there isn't even serin/serout.

The beta version of PICAXE Editor 6 does not include any function like this and only brief hints about it have been released, which are that it will be better than the previous one. It's unlikely that the new version will be compatible with all the PICAXE commands because what would be the point in buying a PICAXE then?

You also need the USB cable AXE027 connected and the USB driver installed.
It seems unlikely that this would be required.
 

srnet

Senior Member
Technical certainly implied that PE6 would include an option to export standard PICAXE programs as assembler for loading into raw PICs.

Discussed in this thread, post #11 onwards.

http://www.picaxeforum.co.uk/showthread.php?23670-Compile-a-BAS-file-as-an-HEX-file-and-upload-to-PICAXE-Possible/page2&highlight=assembler


Q: So a commercial user will have no need to purchase PICAXE chips anymore ?

A: Correct. Obviously compiled BASIC will be quite different (e.g. no debug etc. features via the download cable) but can also be modified to merge assembler libraries (e.g. floating point) etc.
 

hippy

Technical Support
Staff member
To program micro controllers with an assembler code program you require a BAS 800 PIC Programmer, nothing else will work?

The BASIC to Assembler conversion function will also not operate unless the BAS 800 PIC programmer is attached to the Window based PC with the PE6 Editor running.
That is not the case as I understand it to be. From post #20 of the same thread linked to by srnet above ...

http://www.picaxeforum.co.uk/showthread.php?23670-Compile-a-BAS-file-as-an-HEX-file-and-upload-to-PICAXE-Possible&p=235612&viewfull=1#post235612

PE6 Beta does not include conversion to Assembler support at present. This will be a future addition to PE6.
 

CDRIVE

Senior Member
That is not the case as I understand it to be. From post #20 of the same thread linked to by srnet above ...

http://www.picaxeforum.co.uk/showthread.php?23670-Compile-a-BAS-file-as-an-HEX-file-and-upload-to-PICAXE-Possible&p=235612&viewfull=1#post235612

PE6 Beta does not include conversion to Assembler support at present. This will be a future addition to PE6.
This is an old thread but at the time of this post PE6 still can't export as ASM. Is it ever really going to happen?

Chris
 

stan74

Senior Member
Hi.I'm new to picaxe and can't find any reference to assembler in PE 6.0.8.11.
Is picaxe code compiled machine code with a runtime library or tokens that are interpreted one at a time?
My analogy is 80's ZXspectrum with it's slow interpreted basic and compilers for the it that produced compiled readable Z80 assembler that ran 20 times faster.
You could always call machine code routines for interrupt sound or sprites in basic.
 

stan74

Senior Member
You get this feature is inactive in this beta. Of course you do. You'd have to pay £200 for this feature and PE would be dongle protected.
I didn't know PE was beta. Normally betas fall over.Only bug I found is high lighting text and right click copy and the text disappears.
I'll search for PE5.
 

CDRIVE

Senior Member
Click "File" then click "Export". You'll then see the options there to select "Assembler Export".

BTW, I love the simplicity of the Picaxe system and have no desire to endure the royal PTA that's involved in programming blank PIC's. The fact is Picaxe has always satisfied any uC project I've thrown at it while keeping me very comfortable in all versions of their editors and now their IDE. What I don't like is Picaxe VSM, which is the only Spice simulator that supports Picaxe. I find it stable but extremely clunky. So in order to enjoy the comfort of the Picaxe IDE but use my favorite Spice app (TINA) I must convert Picaxe Basic to ASM or HEX. I can then import the ASM or HEX to TINA to run a simulation using the PIC model equivalent to the Picaxe I'm using. All Picaxe chips cross over to a blank PIC model.

Chris
 

CDRIVE

Senior Member
I forgot to mention that I fully understand the financial issues for REV ED to freely convert PicaxeBasic to ASM but I have no desire to use PICs. What I really would like to see is a Picaxe - DesignSoft (TINA) coalition. Heck, I can build a circuit in TINA in a small fraction of the time it takes in VSM.

Chris
 
Last edited:

stan74

Senior Member
As I said it is disabled in latest PE.I just downloaded latest PE5 and it's an option in the wizard but you need a serial programmer and I only have a parallel port one.It doesn't export a hex file.Sad.
Since I was not aware of this feature it doesn't bother me.I wish I got into Picaxe 15 years ago. A few syntax hurdles at first and not used a pic for 13 years but then banged out an ultrasonic robot program in 2 hours.In circuit programming is handy but that could be done with a boot loader.I used a basic compiler written in turbo pascal 15 years ago and that was brilliant but for obsolete pics.
Picaxe,without trying it,came over as something for school kids like Scratch on a Raspberry Pi or basic stamp thingy.The Revolution Education name as well and how it was marketed then..and now.Microchip seemed more engineering and adult and serious.
My friend mentioned he was interested in an arduino but when I see him next I recommend picaxe although he's never written a program I don't thing C++ would be a good entry point.As he's an industrial electronics engineer he could build loads of things easily with a picaxe if only he could code.
 

srnet

Senior Member
This is an old thread but at the time of this post PE6 still can't export as ASM. Is it ever really going to happen?
Chris
Its been 3 years of waiting.

Even the most hopeful would have assumed a long time ago that its not going to happen.
 

stan74

Senior Member
I live in Cardiff to SRNET.Maplins Newport Rd. sell a serial programmer for £9.I try to send it to a file.
 

stan74

Senior Member
Sorry.I meant fool PE into sending the file to another machine.PE detects a programmer.Find out how a compatable one works and use a terminal to talk to PE...or maybe not.
 

nick12ab

Senior Member
The PE5 feature requires the BAS800 from Rev-Ed, not just any serial programmer. Few BASIC commands were actually available (apparently serout wasn't one of them so it would really just be a higher level assembly language), so you would just be wasting money on an old programmer which could have been spent on a PicKit3, and only slightly delaying the inevitable of having to learn C.

To answer your earlier question, PICAXE code is interpreted.
 

CDRIVE

Senior Member
Sorry.I meant fool PE into sending the file to another machine.PE detects a programmer.Find out how a compatable one works and use a terminal to talk to PE...or maybe not.
Thanks for the explanation.

The PE5 feature requires the BAS800 from Rev-Ed, not just any serial programmer. Few BASIC commands were actually available (apparently serout wasn't one of them so it would really just be a higher level assembly language), so you would just be wasting money on an old programmer which could have been spent on a PicKit3, and only slightly delaying the inevitable of having to learn C.


To answer your earlier question, PICAXE code is interpreted.
It wasn't me that asked that question. All flavors of Basic are interpreted languages. That said if I wanted the pain I wouldn't choose "C" as ASM is the next level up from true machine (BIN) code. I don't think there's any language that comes closer for PC's or PICs. Both C and ASM are about as much fun as having a root canal but if one must endure the pain ASM makes more sense to me. Especially since a complete list of ASM instructions are supplied with every PIC model datasheet.

Thanks anyway though.

Chris
 

Jeremy Harris

Senior Member
All flavors of Basic are interpreted languages.
Chris
My understanding is that this is wrong and there have been compiled versions of BASIC available for some time now. I recall coming across a compiled version some years ago, Swordfish, and thought about trying it, but got distracted by something else. I believe that there are other true compiled version around too, but I only looked at Swordfish as it was specifically aimed at PICs.
 

stan74

Senior Member
Compiled is executable code in the processors native command set.No interpreting at run time.
Compiled code is slower but how much depends on the compiler.
A picaxe program I'm writing uses 23 gosubs to make it readable. If I was concerned about speed the code would be inline.
Most code has pauses anyway.My robot program uses ultrasonic and I have to pause 10 ms between pulses.I wonder if the rest of the program takes 10 ms to loop.
 

CDRIVE

Senior Member
Yes exactly but even Swordfish first interprets the Basic typed into the editor and converts it to ASM. And yes again that it compiles native code into the PIC. By the way, I've had a copy of SF for at least a year or two. I just wish it supported PIC16 family chips. I find its syntax comfortably similar to VB6, which I'm very much at home with. I've owned my copy of VB6 Pro since 1998.

Chris
 

srnet

Senior Member
Yes exactly but even Swordfish first interprets the Basic typed into the editor and converts it to ASM
So in your eyes (and probably your eyes only) Swordfish is an interpeter too ?

If you mix terms like that virtually everyone will be confused because that is not how the terms are used within computing.

https://en.wikipedia.org/wiki/Interpreter_(computing)

"In computer science, an interpreter is a computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, without previously compiling them into a machine language program."
 
Last edited:

tmfkam

Senior Member
I have started to use (extensively, at home and at work) a freely available 'Basic Language' compiler that takes in Basic code, builds it into assembler then compiles it into a 'hex' package for uploading to a target PIC device. In my case, this is the 16F1825/1829 devices.

Had PE5 or PE6 been available for the Mac, I may have used more PicAxe devices, but as I have to use MacAXEpad (or run PE under an emulator) which doesn't have the wonderful emulator of PE5/6 I may as well use the opposing Basic editor.

Sadly, by not fully supporting the Mac, my PicAxe use is in (terminal?) decline.
 

Jeremy Harris

Senior Member
So in your eyes (and probably your eyes only) Swordfish is an interpeter too ?

If you mix terms like that virtually everyone will be confused because that is not how the terms are used within computing.

https://en.wikipedia.org/wiki/Interpreter_(computing)

"In computer science, an interpreter is a computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, without previously compiling them into a machine language program."

That entirely matches my experience of playing around with microprocessors since the early 1980's.

AFAICS, the various BASIC compilers around are no different to C compilers or other compilers; they take the source code and create machine object code that the chosen target chip can directly execute.

The Picaxe doesn't do this, as there is an on-board interpreter in every Picaxe chip that interprets the compiled (to token level) source code to machine instructions in the chip.
 

stan74

Senior Member
RE calling PE a compiler? If you put a picaxe in a programmer and looked in eeprom the readable code would be the serial and interpreter.The program would be unreadable.
 

hippy

Technical Support
Staff member
Don't forget that the process of compilation, the conversion of source code to a machine object code, is separate to the execution of that machine object code.

Probably the most accurate way of describing a PICAXE chip is as a virtual machine which has its own machine object code defined which is interpreted by its firmware.

A 'machine object code', the chip's 'instruction set' is the lowest level at which a program to be executed could be specified, whether that is native or virtual.

Converting PICAXE Basic source code to that machine object code, albeit a virtual machine object code, makes the part doing that a compiler.

Java probably has most parallels to a PICAXE system; implementations are usually based upon a Java Virtual Machine (JVM) which interprets bytecode and the Java compiler converts source code to that bytecode. It is still considered a compiler because it is generating bytecode, 'object code' for the virtual machine which processes that object code, even though it is not generating 'native object code'.
 

stan74

Senior Member
I knew it was run time compiled 15 years ago so didn't use picaxe,which was a mistake. Picaxe is fast enough for what I want and it lets me do what I want faster. I was given a 2 pass pic basic compiler 15 years ago that produced a readable "hex" file.The code had lots of calls to subroutines to handle certain commands so was 2 to 3 times bigger than the same program written in mnemonics.The guy who wrote it gave me V1 to V3 improving it from integer to 16 bit and pwm.But the extra basic command libraries made the code bigger even if the features weren't used.He wrote it for an Australian company.
 

CDRIVE

Senior Member
Below is what my conception of a programing Interpreter is. The first block being the Interpreter as apposed to a Compiler. Yes, I realize that the Picaxe system does not follow this procedure, as Hippy has described. In this case I'm talking about blank PICs only. Not Picaxe, Arduino's or any other uC that utilize on board Bootloaders.

Because this thread or my "Interpreter" comments seemed to ruffle some feathers I did read the Wiki link that was posted. Unfortunately it confused my 70 year old brain more than it's already been. I then did some Googling and found this explanation that didn't send by brain into an indeterminate loop!
http://www.best-microcontroller-projects.com/pic-basic.html

ChrisBasicProgrammer.png
 

Jeremy Harris

Senior Member
Not sure about that diagram at all. In general, interpreters work with either ASCII text files (examples being pretty much all the early versions of BASIC that ran on things like the BBC Micro, MS-DOS PCs, and many other machines) and then interpret each command, in sequence, into a combination of machine code instructions that the computer or microcontroller directly executes. The process is bidirectional, in that output from the computer or microcontroller is interpreted back into ASCII text to be displayed to the user. This is a real-time, sequential, process.

True, compiled, programming languages, including many forms of BASIC, take the text source code instructions and compile these into machine code that is specific to the type of processor being used. Some do this in a single pass, some older systems used to do this in two passes, with something similar to assembly language being the intermediate output that was then fed into the second stage compiler to generate the machine code that could be executed.

I think the confusion comes in with the Picaxe in that it is a bit of a hybrid system. The programming editor essentially does nothing more than generate a source text file, in ASCII initially. In fact you don't need to use the Programming Editor to write a Picaxe code file, any plain text editor will do the job.

When you programme a Picaxe chip, the text source code file is first compiled to a shortened, token form, and this is what gets sent and stored in programme memory in the Picaxe chip. It is not assembly code, it's a tokenised form of the original text instructions, with all the unnecessary text removed, to save memory space.

When the Picaxe runs the code from the programme memory, the on-board interpreter does essentially the same function as the BASIC interpreter in something like BBC Basic, or GW BASIC on MS-DOS machines, with the only difference being that instead of interpreting long text instructions in sequence, it interprets shorter tokens that are a representation of those longer text instructions.

So, the key difference between a PIC running the Picaxe on-board interpreter and a PIC programmed with a compiled BASIC, is that the Picaxe will still interpret the tokenised programme, sequentially, every time it executes, so there is a delay time for each and every instruction, whereas the compiled BASIC will run natively, as the programme stored in the PIC programme memory will already be in the form of machine instructions - no on-board interpretation needs to happen, so the code executes very much faster.

The downside of using compiled BASIC is that it is very much harder to debug the code. The interpreter built-in to every Picaxe includes some quite powerful debugging tools, that allow quite a lot of visibility as to what the programme is actually doing via the terminal screen, whilst it's actually running. This is the really big advantage, the thing that makes programme development with a Picaxe easier and quicker. The trade off is execution speed, when compared to a compiled language, but that has next to no impact for a large number of projects, where execution speed isn't really an issue.

One option this gives is to develop and debug a programme using Picaxe BASIC, then, if you really need much faster execution speed, convert the Picaxe source text file into a form that is compatible with one of the compiled versions of BASIC. This isn't wholly straightforward, as there are differences between the commands available between different flavours of compiled BASIC, but is can be done with a bit of patience, and the cost of the BASIC compiler needed.
 

stan74

Senior Member
Not sure about that diagram at all. In general, interpreters work with either ASCII text files (examples being pretty much all the early versions of BASIC that ran on things like the BBC Micro, MS-DOS PCs, and many other machines) and then interpret each command, in sequence, into a combination of machine code instructions that the computer or microcontroller directly executes. The process is bidirectional, in that output from the computer or microcontroller is interpreted back into ASCII text to be displayed to the user. This is a real-time, sequential, process.

True, compiled, programming languages, including many forms of BASIC, take the text source code instructions and compile these into machine code that is specific to the type of processor being used. Some do this in a single pass, some older systems used to do this in two passes, with something similar to assembly language being the intermediate output that was then fed into the second stage compiler to generate the machine code that could be executed.

I think the confusion comes in with the Picaxe in that it is a bit of a hybrid system. The programming editor essentially does nothing more than generate a source text file, in ASCII initially. In fact you don't need to use the Programming Editor to write a Picaxe code file, any plain text editor will do the job.

When you programme a Picaxe chip, the text source code file is first compiled to a shortened, token form, and this is what gets sent and stored in programme memory in the Picaxe chip. It is not assembly code, it's a tokenised form of the original text instructions, with all the unnecessary text removed, to save memory space.

When the Picaxe runs the code from the programme memory, the on-board interpreter does essentially the same function as the BASIC interpreter in something like BBC Basic, or GW BASIC on MS-DOS machines, with the only difference being that instead of interpreting long text instructions in sequence, it interprets shorter tokens that are a representation of those longer text instructions.

So, the key difference between a PIC running the Picaxe on-board interpreter and a PIC programmed with a compiled BASIC, is that the Picaxe will still interpret the tokenised programme, sequentially, every time it executes, so there is a delay time for each and every instruction, whereas the compiled BASIC will run natively, as the programme stored in the PIC programme memory will already be in the form of machine instructions - no on-board interpretation needs to happen, so the code executes very much faster.

The downside of using compiled BASIC is that it is very much harder to debug the code. The interpreter built-in to every Picaxe includes some quite powerful debugging tools, that allow quite a lot of visibility as to what the programme is actually doing via the terminal screen, whilst it's actually running. This is the really big advantage, the thing that makes programme development with a Picaxe easier and quicker. The trade off is execution speed, when compared to a compiled language, but that has next to no impact for a large number of projects, where execution speed isn't really an issue.

One option this gives is to develop and debug a programme using Picaxe BASIC, then, if you really need much faster execution speed, convert the Picaxe source text file into a form that is compatible with one of the compiled versions of BASIC. This isn't wholly straightforward, as there are differences between the commands available between different flavours of compiled BASIC, but is can be done with a bit of patience, and the cost of the BASIC compiler needed.
Mpasm,Microchips assembler is 2 pass like some compilers because the jump and call addresses can't be done until the second pass.
 

Jeremy Harris

Senior Member
Mpasm,Microchips assembler is 2 pass like some compilers because the jump and call addresses can't be done until the second pass.
I well remember working with 2 pass compilers 35 years ago, when we wrote code on a Teletype, transmitted the paper tape (at 300 baud) to the computer centre, where it would be compiled during the overnight down time and sent back for checking the next morning. I don't think I ever, once, had a programme go through both compilation stages in one night, so the shortest possible programme compile time was 48 hours, if you were lucky enough to spot all the errors on the first lot of code that failed to compile................
 

stan74

Senior Member
Writing compilers is a subject in itself.I used 6502 & z80 compilers in the 80's,all were 2 pass like mpasm was (still is?).A lot of programs then were compiled basic.If you had such a program,the compiler was in the program and you could use it to compile another basic program.So you got a free compiler. The code produced was native but contained run time routines from the compiler which was around 4Kb. So 1 line of compiled basic would be 4Kb. Happy days :)
You have to compile programs, or builds, on a Raspberry Pi,which can take all night.
 

johndk

Senior Member
Okay. So I'd like to distill this discussion to something practical. I like developing on the PICAXE (I use 28x2 almost exclusively) because it is fast and easy. The chip and (compiled/interpreted) code function fast enough for most applications. And the chip is very frugal on power consumption. So for me, it is a nice chip for commercial applications. That said, I've been trying to figure out a faster way to turn out production level quantities of chips. Faster than doing the PE download for each chip. I was hoping to find a way to export the PE serial stream that gets sent to the chip as a file and then set up a high speed serial link and just pump this file to one chip after another.

Can anyone offer some suggestions on how to accomplish this? Right now, I'm building a set of 32 chips for my remote sensors. If that's successful, that number will turn into hundreds or (hopefully) more. I need a fast way to program them.
 

Jeremy Harris

Senior Member
I'm pretty sure there is a way to do what you want, but not using PE. IIRC, somewhere on here there is a description of a method for taking text source code files (.bas files) and then running the compiler/loader part of PE on it's own to programme Picaxe chips. I may be wrong, but I think this can be done with a fairly simple script, that calls the programme source file and sends it to the compiler/loader.

The problem is really speeding up the time it takes to download to the chip and to change chips over. You can speed things up by using a real RS232 port on a PC, I've found, and I believe there's a way of speeding up the AXE027 slightly, too, by tweaking some settings. You could probably set up a system with a script that just required you to change the chip, and press a key to programme the next chip, then halting to allow the change of chip once the programme had downloaded.

TBH it's not something I've looked at in depth, I only looked at it when Axepad was flaky on my Linus machines, and this looked like a possible way to get around using it. Others here will know far more about it, and whether or not it's practical to do for your task.

Finally, I seem to recall that Rev Ed once offered a service the programme Picaxe chips for a modest fee, so they could be supplied with the user programme already loaded. I may have that wrong, as it's something I thought I read about some years ago.
 

hippy

Technical Support
Staff member
The download speed is fixed by the firmware so there is no way to get a program into a PICAXE quicker than when it is downloaded through PE6 etc.

Including #NO_DATA and #NO_TABLE directives in the source program can reduce the download time when they are able to be used.

Settings for the serial port can sometimes have an effect. If the latency is set too high the computer may run something else before coming back to check that downloaded data was verified and sending the next. How to adjust latency times for the AXE027 cable is described here -

www.picaxe.com/docs/axe027_settings.pdf

As Jeremy notes we do offer a pre-programmed PICAXE service for which there is a small additional unit cost per PICAXE plus a setup cost and I believe there is a minimum order quantity of 500 required as well.

The quickest way to program smaller quantities is probably a home-built ZIF-socket programming jig, a spare laptop with the command line compilers installed, an X.BAT batch file with the appropriate compile and download command and just keep hitting "X" then carriage return.
 

stan74

Senior Member
Does that mean a picaxe chip can't be copied.Can it be read including the boot loader? I don't have a programmer to test.
 
Top