Connect with us

New Programming Language Anyone?

Discussion in 'Microcontrollers, Programming and IoT' started by Raven Luni, May 24, 2013.

Scroll to continue with content
  1. Raven Luni

    Raven Luni

    798
    7
    Oct 15, 2011
    Greetings,

    So I finally bit the bullet and ordered a bunch of PICs (I had been avoiding MCUs for a while mainly due to having had enough of programming plus wanting to get more familiar with 'real' circuits).

    Anyway, just starting to read up and from what I gather, C and Assembler are pretty much the only choices for programming - fine for the likes of me but I'm aware there are alot of people who just want to do fun stuff and arent particularly software minded.

    Would it be worth my time developing a high level language that people wont give people a headache (this is something I specialise in and could do very easily)? Maybe it could be made common across a range of different processors. I would probably want to go commercial with it since I'm now out of a job and need a source of income.
     
  2. BobK

    BobK

    7,682
    1,685
    Jan 5, 2010
    I myself would like to do the same. C is not really that good a fit for programming small micros. I would like to see a language that supports multitasking, at a very simple level, and supports fixed point numbers directly.

    But I think we would have a hard time convincing anyone to use a new language.

    Bob
     
  3. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    Isn't this what is done in the PICAXE solution? I think you should include BASIC into the list of languages, even if you need to use a primed PIC to use it.

    If you could make a simple compiler/programmer with 'no' limits, starting with a noob level and expandable to 'expert' level. I would buy it, if not too costly. Just for the fun of it.
     
  4. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    That's the reason you have to make it GOOD! The problem with all compilers and IDEs are the complexity, combined with all the good intentions of making them go away. this makes it a pain to make adjustments and changes, without a very steep learning curve.

    Personally I'm interested in concentrating in the program I want to make, not all the glorified tricks and traps to get it twisted through the mill.
     
  5. BobK

    BobK

    7,682
    1,685
    Jan 5, 2010
    Well, that seems to be what Arduino and PICAXE are about. Have you used either of them? If so, what are their strengths and weaknesses?

    Bob
     
  6. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,384
    2,771
    Jan 21, 2010
    If you look a little harder you'll find basic and pascal are both available for many uC's

    Pascal, in particular, is has a lot of advantages over C.

    But C is the HLL that (almost) everyone uses.

    As for the comment about multi-tasking, it's really not an issue if you design your code properly. As long as you control which task has control of various peripheral devices, and write your code so that each tasks falls through and never calls "delay", most problems go away.

    It may help to consider your tasks as a series of state machines, although you don't need to formally code them as such.

    For a beginner example of how to do this, look in this thread.
     
  7. Raven Luni

    Raven Luni

    798
    7
    Oct 15, 2011
    Holy crap - people are making real money from this. I had at least expected a mountain of free / open source stuff to the point where only the really high end stuff would be worth selling.
     
  8. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,384
    2,771
    Jan 21, 2010
    There are open source alternatives. In many cases the GNU C++ compiler is used (for example -- see the Arduino platform).

    There are other compilers you can get free. Some have restrictions on code size or optimization in the free versions.

    As much as you or I might dislike C++, the facts are that sample code is likely to be found in this language, and the compiler is generally pretty good.

    It's actually a pretty simple language once you get the hang of it.

    The main thing to remember is NEVER write something like this:

    If (i = 1) then...
     
  9. donkey

    donkey

    1,286
    56
    Feb 26, 2011
    I find programming to be a headache I know this is only because when I get stuck and try to find the solution my head starts hurting as it gets people trying to explain the physics behind a computer when all I want to do is be able to find the right way to type the line
    If (I=1) then.... lol
    also upper and lowercase catches me out all the time. As you see from most of my posts I rarely use the shift key. its bad habit but dang it I want the compiler to look and see if the text I am typing should be in upper or lower case.
     
  10. gorgon

    gorgon

    603
    24
    Jun 6, 2011

    Do you know of any comparative tests, of the actual overhead or code size between Assembler, C and C++?

    Without knowing, I would suspect the the overhead of C++ is more than C?

    Assembler size is of course, maybe more than for C and C++, dependent of the actual skills of the programmer.

    How many of the smaller microcontrollers used in DIY projects have a decent C++ compiler? My experience is that you need to be on a 32bit controller before this is true, but I may be outdated here.

    I would think that C is the HLL for small micros, if you don't get into assembler. With a good macroassembler, it is possible to make 'HLL like' reusable structures.
     
    Last edited: May 26, 2013
  11. Raven Luni

    Raven Luni

    798
    7
    Oct 15, 2011
    It depends both on the compiler and the coder. The best compiler's will be optimised to the point where there is no difference. The stack based calling convention (which is by default what the C family uses) is usually the first point of deviation. You have to push the parameters, call the function, either shift the parameters into registers or indirectly address them (usually with BP in x86) which can require a couple of extra clock cycles, then they have to get popped on exit.

    Pascal is actually better in that respect since it uses the register calling convension by default. The first few are assigned to predetermined general purpose registers before using the stack.

    A good compiler for any language should have all of these methods available. A really good one will be able to determine whether a function call is necessary or the code can be written as a macro (repeatable set of inctructions written inline).

    At the end of the day when you know what youre doing, nothing beats working at the lowest level possible.
     
  12. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    When you work in embedded systems, there is warnings in the litterature, not to use optimising, when operating directly on hardware devices, even if you type them as volatile.
     
  13. Druzyek

    Druzyek

    5
    0
    May 29, 2013
    Hi guys,
    I'm new here but this is an interesting thread so I'd like to add my two cents.

    This comment comes as a bit of a surprise! Although it technically is a high level language, C is about as close as you can get to the actual hardware before using assembly. Languages like BASIC that make things "easier" have more overhead, which you should avoid on a micro. C is the only language I would ever use for microcontrollers.

    No language supports them "directly." You can do this in C with a library which will be slow but any other language that supports them will also use a library and also be slow.

    You should know that the BASIC on PICAXEs is interpreted. This means that your code is never actually turned into machine code so it is much slower.

    The MSP430 is a 16-bit micro that you can use C++ on. I prefer C myself but people who use C++ templates can make some really handy code without making their programs any bigger. I thought C++ added a lot of overhead too until I found out about this.

    Maybe this is the default but I doubt there are many compilers for microcontrollers, C or otherwise, that push to the stack when there are empty registers. Pascal does not offer an advantage here. People have been working on compilers for a very long time and nowadays they are more than smart enough not to waste registers when only a few hundred bytes of RAM are available.
     
  14. BobK

    BobK

    7,682
    1,685
    Jan 5, 2010
    When I said C was not well suited for programming micros, I was not thinking about Basic as the alternative, I was thinking about Ada. Ada was designed for embedded programming and does support fixed point numbers and multi-tasking. And it does these in a way that they can be implemented very efficiently.

    A full Ada implementation is not what I would go for, but using some of it's concepts in a simpler form.

    Fixed point numbers can be implemented efficiently without libraries. Adding or subtracting two fixed point number of the same type is the same as the operation on integers. Multiplying and dividing merely need another shift to normalize the result. Conversions from one fixed point type to another is a just a shift.

    Bob
     
  15. Druzyek

    Druzyek

    5
    0
    May 29, 2013
    Bob, I am not familiar with Ada but it sounds interesting. From what I just read it seems like a fairly high-level language. What do you like about it better than C?

    I have worked with big numbers before and fixed point is a little more complicated than what you are describing. The process you describe is exactly what I mean by "library." In other words, you would need several lines of code to add two numbers rather than just a single assembly instruction. That is a limitation of the hardware and any language would need extra code to do it. Multiplying and dividing are also a bit more complicated than just shifts.
     
  16. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,384
    2,771
    Jan 21, 2010
    Don't confuse the language with the back end of the compiler or the code it generates.

    There is no particular reason why a language corresponds to the calling convention. The use of the stack (where available) is useful for re-entrant routines or (more importantly) recursive calls, but unless the interface is available externally (i.e. an API), the compiler can make a decision as to what to do.

    C for example was designed around the instruction set of the PDP-11 computer and it's CPU's addressing modes (similar to the Motorola 68k). The computed GOTO of Fortran was apparently designed around a particular assembler instruction available on a certain IBM mainframe. Neither of these mean the language can't run very well on other hardware.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-