The Assembly Language Debate

bluejets

Senior Member
I do assembler. I do not need assembler on the PICAXE. I hope young programmers learn assembler because I think it gives an appreciation of what the higher language must do to perform a task; it may even make them better programmers because knowledge has a way of widening ones horizons.

- Ray
Presently trying to work my way through this ...... http://www.gooligum.com.au/tut_baseline.html .....thinking it was a natural progression from picaxe to C ....... so you believe it is not a waste of time then ..??
I read about many projects, some that become stumped and not working the way they should. I have a 50 year background with electrical, plc's and electronics and often look at the programs and think well, surely they learn how to do it so It can't be all that hard to do.
 

SD70M

Senior Member
What do you want your "future progression" to be? Hobby or employment?
The only reason for asking was another thread which mentioned the comparatively slow processing of the picaxe using basic and having to convert it onboard, compared with the arduino, for example. But I think I may have misunderstood something somewhere.

If the arduino is used, and I were to write the program in C or some other higher language, I'm now assuming it would still need to be compiled before loading onto the arduino chip, and as pic basic can be compiled then the same can be acheived with that. Have I got that right?

Angie
 

SAborn

Senior Member
Not sure here but did Lewis Hamilton or Jenson Button (topical) learn in an F1 car or start with go-karts?
Angie
Very true but they joined a platform that supported their stage of learning (go-karts) and moved up to F1 being a different platform, and that was my point, if you want to use a different platform (ASM) than join a group that supports that platform like a Pic group/forum.

If you want to use Picaxe (go-Karts) then programming is in basic, and if you want F1 (ASM, C++, etc) then move to a group who supports that.
 

SD70M

Senior Member
Very true but they joined a platform that supported their stage of learning (go-karts) and moved up to F1 being a different platform, and that was my point, if you want to use a different platform (ASM) than join a group that supports that platform like a Pic group/forum.

If you want to use Picaxe (go-Karts) then programming is in basic, and if you want F1 (ASM, C++, etc) then move to a group who supports that.
I understand that but as I'm new to picaxe and tried them to see what they could do, especially for me, Ijoined this picaxe forum. But surely that doesn't stop someone who is interested in, but has no knowledge of other options, asking a thick civilised question? I have no idea of the difference and as assemly language was mentioned I thought I'd try and pick the brains of the more informed among the forum.

Believe me, as far as I can see, the picaxe is fine for what I need at the moment but I was just interested in other options, not knowing too much about them.

Sorry for asking.
Angie
 

srnet

Senior Member
If the arduino is used, and I were to write the program in C or some other higher language, I'm now assuming it would still need to be compiled before loading onto the arduino chip
Yes, thats what the Arduino setup does, takes your program, compiles it and generates a machine code file for the processor.

and as pic basic can be compiled then the same can be acheived with that. Have I got that right?
PICBASIC is a compiled language and works in a similar way, its a product of MicroEngineering that you have to buy.
 

Aresby

New Member
Presently trying to work my way through this ...... http://www.gooligum.com.au/tut_baseline.html .....thinking it was a natural progression from picaxe to C ....... so you believe it is not a waste of time then ..?
I too have worked through this, and it provides a sound introduction to assembler.

That said, once you get past the 4 flashing LED stage things get quite intense and you really do need to apply yourself to get value out of it.

It was at that point I sort of gave up on assembler, on the basis that I wanted to get things done in the real world rather than spend all my time just getting to grips with a low-level language.

It's certainly not a waste of time following that assembler course, and you'll quickly appreciate how PICAXE Basic (and other high level languages) take all that pain away from you allowing you to concentrate on making the chip actually do stuff.
 

westaust55

Moderator
I have no idea of the difference and as assemly language was mentioned I thought I'd try and pick the brains of the more informed among the forum.

Believe me, as far as I can see, the picaxe is fine for what I need at the moment but I was just interested in other options, not knowing too much about them.

Sorry for asking.
Angie
Never a need to be sorry for asking a question.
Neither am I likely to be the most informed with respect to Assembler but have done quite a bit in aeons gone by.

Assembler (or machine code) is in simple terms the native language of the microcontrollers (or microprocessors as used in PC's etc).
Each instruction does just one task, be that to fetch a value form memory, load an immediate value, increment a value, etc.
The work is done in a special register called the accumulator and from there is saved back to memory.

If you want to do something like go around in a loop (such as a For...Next loop) and perform some math on a value each time then you must set up the code to do each step:
1. pre-load the register to be used for the math with a starting value,
2. save the starting value in a memory register,
3. set up an index register for the (For...Next) loop
4. fetch the value saved in step 2
5. perform the math on the assigned register
6. save the modified value in the original memory register
7. fetch the loop index value
8. increment the loop index value
9. save the loop register back to its register/memory location
10. test if looping has completed and if yes leave the loop
11. if not completed, then branch back to step 4.

some chips may for example let you in effect merge steps 8 and 9
Dependant upon the microcontroller/microprocessor, the native math functions may be very limited. Some only to add subtract, others have multiplication and maybe division of sorts.
But often you need to call in a routine from a predefined math library if you want anything more than basic integer +, -, / or *
There are no defined bit, byte or word variables. You (or if writing in high level code, the compiler) must assign register/memory locations for each value to be kept and remember which is which or use definitions akin to the PICAXE SYMBOL statement.


Now the equivalent for the PICAXE is:
1. pre define the starting value and assign to a variable
2. use the FOR variable = start TO end {step x} command
3. perform the math function on the assigned variable
4. call/use the Next command.

Now this is simplified but as you can see, the PICAXE BASIC has less steps.

But underlying the variable assignments and setting up the FOR...NEXT loop are typically many assembler/machine code commands for each BASIC program command.
 
Last edited:

hippy

Technical Support
Staff member
Presently trying to work my way through this ...... http://www.gooligum.com.au/tut_baseline.html .....thinking it was a natural progression from picaxe to C
IMO there is no need to learn assembly language to go from one high level language to another.

You don't need to know what might be going on inside the chip in order to achieve something expressed in a high level language, you only have to know that it will do what you want it to do.

For example, in PICAXE Basic, "HIGH C.0" sets pin C.0 to an output and outputs a logic high signal. It doesn't matter how that is achieved, it doesn't matter whether the code is interpreted or compiled, it doesn't matter whether the command is executed efficiently or inefficiently as long as it achieves what's wanted. It doesn't matter how the same could be achieved in Assembler, in C or in any other language other than when you want to use that other language.

Where knowing assembler can be useful is in seeing what compiled code is generated for a particular high level language in order to judge how optimised the compilation is. For example "pinC.0=1" in PICAXE Basic is likely "PORTC |= 1;" in C, and there are a number of ways that could be expressed in Assembler and one of those will have been chosen by the compiler. Understanding assembler and seeing what it was compiled to will allow one to determine if the compiler made a good choice or not. That's not a prerequisite to being able to program in C though.
 

SD70M

Senior Member
@srnet , Aresby, westaust55 and hippy

Thanks all for the explanations. And that's where I misunderstood. I wrongly assumed assembler was the next evolution of any pic/picaxe/arduino learning curve. Now I've got that I think I understand.

The picaxe is the easiest way to get microchips to do what you want, as it uses a relatively easy language to program it, which is interpreted by the firmware on the picaxe.

Microchip/pic/arduino uses C or C++ (among others) which is precompiled on a PC then that is loaded to the chip. This is harder to do and requires more hardware to link the PC to the chip programmer but, as the code is precompiled it works faster once on the chip.

Is that about right?

Angie
 

nick12ab

Senior Member
Microchip/pic/arduino uses C or C++ (among others) which is precompiled on a PC then that is loaded to the chip. This is harder to do and requires more hardware to link the PC to the chip programmer but, as the code is precompiled it works faster once on the chip.

Is that about right?
Normal PICs and Atmel chips require a special programmer to program the chips. A Microchip programmer can program many different PICs and an Atmel programmer can program many different ATmega and ATtiny chips. They are programmed in Assembler or C but you can also buy a BASIC compiler. These use compiled code and run fast.

Arduino is programmed in a similar way to PICAXE but it requires that the serial port signals are inverted (extra, but low cost, hardware) because it uses the hardware serial port. Arduino also uses compiled code so runs just as fast as a non-Arduino ATmega chip. However, arduino requires a reset in order to program it, kinda like if PICAXE automatically put a disconnect command at the beginning of every program. Arduino is also available in limited pin count variants whereas PICAXE has lots of different sizes.
 

mrburnette

Senior Member
Presently trying to work my way through this ...... http://www.gooligum.com.au/tut_baseline.html .....thinking it was a natural progression from picaxe to C ....... so you believe it is not a waste of time then ..??
Intellectually, knowledge gained from time & effort spent is not a waste of time. The question comes down to are there other things that will advance you further toward a goal than assembly language? I would answer, "Yes."

Spend enough time with it to learn the basics, understand the tools used, and the concepts applied. At that point, make a decision to continue because it is of interest to you or depart with the knowledge and vocabulary. Proficiency is not a requirement to have an appreciation of the technology.

When I taught software classes to adults, I would always spend a day with a PC completely disassembled; I used an old IBM PC system board mounted on plywood and had the IDE hard drive and the floppy all connected with long ribbon cables. Students learned to recognize RAM chips, CPU, PSU, etc. This certainly was not necessary to teach them Lotus 1-2-3, but it made a world of difference in their attitude since they had an appreciation of what was inside the box that performed the magic. A little knowledge goes a long way. Some would add to this foundation over time, others would not advance beyond the visual of a PC exposed on a table. Regardless, no one left the week-long class without the mental imagery; I never had a student complain about 'wasted time' but I surely had many that would approach me on Friday afternoon and offer a note of appreciation for taking the time to provide just a weebit of foundation knowledge.

For those who do not want to get your hands dirty and install all of the required software, libraries, and such... watch a YouTube video or two.

Something like this is probably sufficient to help you determine if you wish to devote more time:
PIC assembler 101

- Ray
 

mrburnette

Senior Member
Many excellent arguments. I especially liked the 'bugger off' argument. At the risk of becoming a pariah, I still think Picaxe would be much better with an inline assembler, or some other method of calling machine code subroutines. But I guess I'm alone on this one. Good luck everyone. I'm off for a drink.
Oh, I am in full agreement. And, I suspect that as the PIC uC's become more powerful, at some point RevEd will be able to provide inline while still restricting the programmer's access to their core firmware (as stated previously, once compromised, the PICAXE has no market protection from clones.) I can envision at least two ways that it could be done today without CPU partitioning if the hosting PIC had sufficient horsepower and more internal RAM.

For example, in a super-PIC world, RevEd hypothetically could encrypt their firmware and download it every time with the user's code; that code being either PICAXE BASIC tokenized source or assembler with the appropriate support libraries in machine language. A digital certificate inside every PICAXE chip would decrypt the RevEd firmware. Such digital certificate would be installed on a write-once basis at the time the PIC was converted to a PICAXE and so labeled.

Another way to pull off such magic would be to have RevEd create a virtual machine within their environment in the PIC. Assembly code from the user would be processed inside this environment and not actually muck with the real hardware without inspection from the VM. In this manner, RevEd could allow assembly but still control the entire process.

Obviously, such hypothetical thinking would require engineering and technology not currently in place. Creating such an environment would provide RevEd with what new marketing capabilities? What new user communities would jump to consume such new designs? Ultimately, would such a venture generate a neutral or positive revenue stream?

I suspect that deep inside some room with the door closed that RevEd is considering their next move... and the next... and... They seem to be a dynamic bunch, advancing their technology across new silicon as the Microchip uC mature and can be had in quantity. I am sure they look closely at threads on the forum about assembly, but I have read no compelling reason why such a capability would be required; in a hobby or educational market. Surely they are aware of the adhesion that Arduino has in the hobby, education, and even commercial markets. Surely they are watching the proliferation of ATmega chips and open software tools. If one can program a PICAXE one can program an Arduino; albeit the investment seems to favor the PICAXE at the moment, but the breath of shields seem to favor the Arduino (my opinion.)

In conclusion, RevEd needs to make a statement to remain relevant outside the UK and the government supported school curriculum... Do they wish a hobby market or are they satisfied with their original charter for UK education? It just may be that RevEd is not completely in control of their own destiny... such things happens when business and government converge. While they certainly have NOT asked for my opinion, I think RevEd should develop an ATmel version of PICAXE with similar tools and the identical PICAXE BASIC command set. But since this is a new effort, why not go ahead and make a full compiler with inline assembly for the ATmel. One could even envision a tool to take existing Arduino library source code and convert it to (for lack of a word, I will invent one) "ATAXE" code. Now, students learning on the easy and well design PICAXE could have a wide-open road beyond the current 'limitations' of an interpreted BASIC.

- Ray
 

hippy

Technical Support
Staff member
Microchip/pic/arduino uses C or C++ (among others) which is precompiled on a PC then that is loaded to the chip. This is harder to do and requires more hardware to link the PC to the chip programmer but, as the code is precompiled it works faster once on the chip.

Is that about right?
Yes.

Raw micros are often programmed using assembly languages or C, the PC converts that into compiled code, which is then loaded onto the chip using specialised programming hardware.

Some micros can also be pre-programmed to contain a bootloader which allows some sort of serial connection to be used to load compiled programs which can be cheaper and easier to use than the specialised programming hardware.

The PICAXE contains a bootloader that allows a standard PC COM Port or a USB-to-RS232 style serial cable to program them, and also contains an interpreter which supports the PICAXE Basic language. This allows the PICAXE compilers to generate 'tokenised executable code' which is more compact than native assembler code but it needs to be interpreted so is generally slower than if it were executing compiled native assembler.

Not all compilers are equal though; some will generate more optimised assembler code than others, some compiled code can be rather inefficient, and some may even compile code into something that is itself interpreted so the gains of compilation over interpreted are not always as great overall as may be expected. Having to make a choice between highest speed and smallest program memory use can also come into it.

Where the PICAXE system scores is in the ease of use and speed of being able to achieve things, a programming language that is simple to use and an integrated programming environment that is fairly straight forward, backed-up by Rev-Ed and PICAXE community support. It is ideal for those the PICAXE is targeted at and many beyond that but a downside is that you may be constrained by what it allows. To get more one has to go to something else which may not be so well integrated or supported, or not so easy to set up, configure, use or learn.

It's probably fair to say, once familiar and competent with any micro and its tools, that all can be used without being problematic. It's just getting there which varies, some are easier to get working with than others.
 

Aresby

New Member
But underlying the variable assignments and setting up the FOR...NEXT loop are typically many commands for each BASIC program command.
Actually, I would have to challenge this.

Certainly whilst there may be certain constructs both in assembler and, say, Basic, that are similar, the whole point of a high-level language is that it abstracts the actual language used from the hardware level.

This can be demonstrated quite well on the PIC front. Write a program for a PICAXE 08M2 and you can run that code on a PICAXE 18X2, even if the firmware has to generate the function differently on each chip. Your Basic program remains the same, however.The only change you would make as a programmer is to tell the compiler for which chip to generate the code.

Take this a step further with object oriented programming. There's no direct correlation between the hardware and any of the software logical constructs; the hardware turns into a black box. Because on the PIC front we directly control the hardware the boundaries are less blurred but I do feel that trying to compare a Basic For/Next loop with its assembler equivalent just encourages people to program down to the hardware level rather than program for the function you're trying to achieve.

A high level language doesn't just simplify the programming, it allows logical constructs and thinking that the hardware has absolutely no knowledge of. That's the job of the compiler / interpreter.
 

Dippy

Moderator
How does that "challenge" what Westy has said (in your quote)?

And what you have said there is true but I think Womai already said much the same about 2million posts ago.
Maybe I just dreamed it.... I seem to have seen all these points before.

If Angie hasn't realised it yet we're starting to enter Fircle mode ;)

PS. Please don't answer my first question - the paragraph count is getting too high ;)
See you later.
 

SD70M

Senior Member
@Everyone who answered me politely

Thank you all for the various explanations etc. I am now clear on microchips and the routes to them.

The PicAxe is a fantastic item and, as has been said, programming it is easy. At the moment it does do what I need but I am now armed with enough info if and when I need to move on to a faster processor. Having said that I am sure, as with the current upgrades to various PicAxe items, that the next PicAxe series will extend it's use even further and probably keep ahead of my learning curve and requirements :)

Angie
 

womai

Senior Member
Actually a great detail is that the Picaxes are just normal Microchip PICs as far as hardware is concerned (maybe with the exception of the very latest M2 series, but even they are pretty close to standard PICs). That means if you really need more speed (or want to reduce the cost for series production) then take the corresponding PIC and program it in compiled C or Basic - it's guaranteed to work if the Picaxe works, since it's identical hardware. Great for rapid prototyping!
 

crowland

Member
From an educational point of view all that adding inline assembler would do would be to allow people to learn about PIC assembly. It will help very little if what you need is assembler for one of the multitude of other devices that are available. I'm not sure the PIC is a particularly good device for learning assembler principles in general because it's structure is quite a lot different to other chips (memory paging for example).

I would stick to it's current strengths - a cheap, easy to use device with an IDE that's suited to rapid development. "Rapid" in an educational environment where you need to explain a new concept, demonstrate it and give the time for the students to practice in a 50 minute lesson makes development systems such as Agile and XP look slow and clumsy.
 

humphpicaxe

New Member
Today I hoped to tie a picaxe to a neopixel. Sad to find that the picaxe is too slow by 3 orders of magnitude to do the job, because of the absence of inline assembler. Back to my Arduino/ATTiny for this job, wish their power management was anywhere near as good as picaxe...
 

John West

Senior Member
I read about the first 5 comments and the last 5 comments, as it was pretty clear where the conversation was headed.

"Sufficient unto the day..." ;)
 
Top