Discussions about using assembler versus C/basic then working with UC

Discussion in 'Programmer's Corner' started by t06afre, Oct 31, 2009.

  1. t06afre

    Thread Starter AAC Fanatic!

    May 11, 2009
    I was just wondering. Has it been any discussions lately about using C/Basic versus Assembler then working with micro controllers or 8 bit CPUs. Even if the thread is old I would like to read postings
    Also how is it with assembler in tech. schools to day?
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    Why don't I move this to the Programmer's Corner and see if it generates interest?
  3. Papabravo


    Feb 24, 2006
    They are all viable tools. Why do you think there is anything to debate? The choice, if there is one, depends entirely on your requirements.
  4. loosewire

    AAC Fanatic!

    Apr 25, 2008
    Did you design your own avartar.
  5. hgmjr


    Jan 28, 2005
    As already mentioned, the choice of which programming language to use is firstly dependent on your application and secondly it is dependent on your programming skill set.

    Assembler (Low Level Language Programming)

    PROs: Assembly language tends to be applied where the time constraints on execution need to be optimal. The low code execution overhead together with the economy of code memory usage, makes assembly language ideal for responding to high frequency incoming signals.

    CONs: Assembly language places a significant bookkeeping burden on the individual doing the programming. This tedium is the primary objection programmers tend to have when using Assembly language programming. Lack of software programmer and portability of the source code over to other devices are also key reasons that Assembly Language is often avoided.

    C/BASIC (High Level Language Programming)

    PROs: The speed of coding is greatly increased through the use of high level languages. High level languages are also generally prized for their tendency to make it easier for another software programmer to pick up the code and determine what the original programmer was trying to do. High level languages also make is possible to take code written to run on one microcontroller to be easily adapted to run on another microcontroller with minimal code changes.

    CONs: High level languages tend to generate a lot of support code that is hidden from the individual program. This additional support code eats up precious memory space and adds to execution time of the code.

    In summary, the decision to use high level versus low level programming languages is driven by the application, amount of program and static memory available, and programmer skill set. Other factors enter into the decision but these are the ones that tend to have the greatest influence over the decision.

  6. ke5nnt

    Active Member

    Mar 1, 2009
    I was given the impression that learning assembly first, gives you a better understanding of exactly how a micro controller works and how information moves around in them, something that programming in C can't do (not my opinion just something I've heard).

    Fact is, I don't know C yet, though I plan to at some point, but having learned Assembly certainly gave me a better understanding of uC's. That was something I'd wanted anyways, because as the type of person who analyzes everything in life, I have a very hard time giving instructions to something without knowing how the instructions are carried out. I always want to know how stuff works, look at some of my threads; someone says "use this part for that", I ask why? what does it do? how does it effect my circuit? Assembly definitely gave me that in regards to the uC.
  7. Frakk

    Active Member

    Jul 6, 2009
    Just to add my 2cents, C/Basic is a lot easier to get started with. You can do things fairly simple, like flash a led, use the ADC, have some inputs/outputs for different things. Programming in C will also give you a fairly good understanding of the control registers and about the peripherials.

    Getting started in assembly will be rather tedious and frustrating if you haven't had much programming and uC experience. Writing the code in C like variable = 2 x 8, takes a lot more operations in assembler, move bits around in registers, do the math, move the bits again and so on.
  8. Eduard Munteanu

    Active Member

    Sep 1, 2007
    Assembly code isn't faster than C code, unless you can beat the compiler at code generation. But the advantage of assembly code is that you have complete control over what happens and you don't need to ask yourself whether or not the compiler does as it's told. Furthermore, there are things which can't be done sanely in C, and you can provide wrappers for asm code.

    That being said, a mixed approach will likely work best. For the same project, some parts might be better written in C, some might be better written in asm. Not only C compilers allows inline asm (C code intermixed with asm snippets), but you can also link assembled asm code and compiled C code, as long as you're familiar with the standard ABI on that platform.
  9. bluebrakes

    Active Member

    Oct 17, 2009
    This is quite an interesting thread for someone who is starting out in pic programming, like myself. I shall have to print this out.
  10. russ_hensel

    Well-Known Member

    Jan 11, 2009
    To really understand a uC study solid state physics, to understand solid state physics study quantum mechanics, to understand quantum mechanics study matrix algebra......

    If you are a beginner and want to get a project done use a hhl ( high level language ) for example: http://www.opencircuits.com/Use_C_for_PIC_Programming!
  11. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    If the fastest event you need to respond to happens every millisecond or so, C or Basic would be fine.

    When you need to respond to micrsoecond pulses (10Khz+), Assembly or a good C compiler will be needed.

    Remember that if just learning assembly, A C or Basic program will often produce a more stable, bug free, and faster program than one in assembly. This applies mostly when working with larger programs, beyond flashing 8 LEDs in sequence.
  12. AllVol

    AAC Fanatic!

    Nov 22, 2005
    If you are very "newbie" at PIC programming, you might want to first explore the PICaxe system. Very inexpensive, very simple and still very effective in learning not only a plain-word Basic language, but a good introduction to PICs themselves and their workings.

    PICaxe chips are available from several sources (google PICaxe) and the editor, complier and programmer are all available for free download.

    If your interest then requires you to go forward, stepping up to PICs and assembly or even embedded C is much easier. If you decide not to go higher, the PICaxe can still produce many useful and meaningful projects.

    Food for thought.
  13. BMorse

    Senior Member

    Sep 26, 2009

    Picaxe uses proprietary software and uses an interpreter, not very efficient..... But if you like designing software in a flow chart environment for blinking LED's :rolleyes:, and have no skill whatsoever in any programming language, then go for the picaxe..:p

    I started out with uC's using the Pic16F84, and a $25.00 programmer from Dontronics....(Pic16Pro Programmer with the 40 Pin Zif socket see attached picture)...... and it was the cheapest route for any one wanting to try out uC's..... I used MPASM, and now I have the REAL ICE, and the pickit 2 also.....

    But for someone who didn't have any knowledge in assembly, or uc's for that matter and just picking things up, Pic uc's and assembly seem to have more help/examples available on the net for any newbie, more so than AVR's and others..... and I also learned C with Microchips C compiler, now I use both C and Assembly, and sometimes there is a call for mixing both to accomplish a task...... but when writing code for a PC based application I always turn to Basic, (Visual Basic that is....), for Pocket PC apps, I use a combination of Embedded C or Embedded VB, so the programming language is really not the issue, but what is the best way to accomplish a task with less overhead and/or lines of code......

    My .02
    Last edited: Nov 22, 2009
  14. t06afre

    Thread Starter AAC Fanatic!

    May 11, 2009
    Then it comes to programming uC's the difference between assembler and C/basic, is not so big. But yes it is differences and using C/Basic will probably save some coding time. Then it comes to uC's and programming I think the most important thing is to know your device. Using C/Basic will never remove the need for studding the data sheet thorough.