Poll

What programming Language do you use for micromouse?

C / C++
22 (81.5%)
Assembler (ASM)
4 (14.8%)
Basic
1 (3.7%)
Pascal
0 (0%)
Java / Scripting
0 (0%)
Other
0 (0%)

Total Members Voted: 24

Voting closed: 13 June, 2006, 12:28:45 PM

Author Topic: What programming Language do you use?  (Read 10093 times)

0 Members and 1 Guest are viewing this topic.

andynxn

  • Administrator
  • phpBB Member
  • *****
  • Posts: 56
    • http://www.re-mastered.co.uk
What programming Language do you use?
« on: 13 June, 2006, 12:28:45 PM »
Thought i would start this forum off with a good over veiw question  :grin:

peteh

  • Administrator
  • phpBB Senior member
  • *****
  • Posts: 512
(No subject)
« Reply #1 on: 14 June, 2006, 08:18:03 PM »
I have several reasons for using C:

First, the code is much more portable. All my general algorithms should compile on just about any compiler for any processor. If you wanted to see my search algorithm, it is readable without any knowledge of what machine it was run on and you could probably just drop it right in to your code.

Second - productivity. It is just plain quicker to write working programs in a high level language. Reason one is part of this. I can write and test algorithms on my PC and then compile them for the mouse.

Third, who needs to learn the madness that is assembler language. Not only is it different for each processor, in this day and age it is just not necessary. Fine when all you had was 256bytes of RAM and a couple of K of ROM. I am more than happy to accept a (relatively small) hit on code size and performance compared to the productivity and portability benefits of a high level language.

Fourth - where would I have such fun arguing with the pro-assembler folk?

Pete

Rich

  • phpBB Senior member
  • *****
  • Posts: 210
    • http://micromouses.blogspot.com/
(No subject)
« Reply #2 on: 21 June, 2006, 12:42:33 PM »
I only use C for the reasons mentioned by Pete.

I have leared a bit of assmebly, just so i know whats going on - like driving a car, i learned to set the points etc (shows age of my cars :P) before i drove just in case anything goes wrong ;).

But thats it, i do not want to grapple with implementing an algorithm in code, i like to prove alorithms on the simulator i writ, then just dag and drop into my MCU C COde. Makes life a lot easier - i do not want to battle with how the MCU is actually implementing my algorithms :P

Mark

  • phpBB Member
  • *****
  • Posts: 60
(No subject)
« Reply #3 on: 21 June, 2006, 01:06:54 PM »
Quote
Fourth - where would I have such fun arguing with the pro-assembler folk?

Since no one else wants to argue :)

I have programmed quite a few micros in C (mainly the ones I didn't know much assembly for) and I always say if you can use assembly then do so.  With the ST7 micros I have had no end of minor compling bugs and workarounds, and doing PID calculations and scaling values was so inefficent, I've ended up with more assembley in time critical fuctions than C code.  I once wrote a single direction PWM speed controller using a PIC12C508 runing at just over 2kHz with 32 steps and reading 1-2mS RC servo pulse input.  It gave me 15 instructions for each PWM update and inbetween this to time the RC pulse.  Try doing that in C.

I have always found bugs in C in almost everything I've done, so If you really need reliability use assmebler.  These days code size isn't that important as most new devices have plenty, but I find programs much more relialbe if its in assembly, and not using other peoples code & libarys.

MichaelB

  • phpBB Member
  • *****
  • Posts: 70
(No subject)
« Reply #4 on: 22 June, 2006, 04:49:23 AM »
Quote
With the ST7 micros I have had no end of minor compling bugs and workarounds

C compilers tend to be inefficient on small/limited ability microcontroller's because they usually have small instruction sets, are only 8 bits wide, limited stacks, and very few registers etc.  Therefore, C can't be implemented very well on small processors.
The compilers tend to be buggy (on these small embedded microcontrollers) because there are few customers to sell to and so limited resources for the compiler writing company and too few users to report bugs in the compiler.

Quote
I've ended up with more assembley in time critical fuctions than C code

Yes, if a function is very time critical (and/or it is a relatively slow processor), then you do really need to code the very time critical parts in assembly language.
But this does not stop you writing the other >=95% of the code in C.

Quote
I have always found bugs in C in almost everything I've done, so If you really need reliability use assmebler


As programs get bigger and bigger (especially when larger teams write the software), C becomes more and more reliable and efficient (relative to assembly language).
Massively large Assembly language programs can be a real nightmare to keep reliable and working (speaking from experience).  I have found it very common for large assembly language programs to just simply crash totally (i.e. not respond to anything, no output etc), after making modifications.  Making it very difficult to debug, as you are not getting any clues as to what is wrong.

What if you want to upgrade to a bigger microcontroller (with a slightly different instruction set) or even a completely different microcontroller, now or in the future ?
If you have written the code in e.g. C, you can quickly port it over to the new micro.  Only needing to re-write the low level I/O drivers.
But in assembly language, you will have to re-write the entire 10,000 (?) source code lines, which are usually much harder to understand than C.  Good luck !!  :cry: , I know which I would prefer  :)

peteh

  • Administrator
  • phpBB Senior member
  • *****
  • Posts: 512
(No subject)
« Reply #5 on: 22 June, 2006, 03:28:28 PM »
Well, the 12C508 speed comntroller is a perfect example of rule 3. When you have limited resources and a serious performance issue, the use assembler. no argument from me.

I have a couple of 8 pin AVR processors doing quadrature decoding at up to 200kHx to generate up and down counts. Clearly that is in assembler. However, in that case it was purely from a masochistic curiousity. The LS7183/4 do a better job for a couple of quid so when they arrived, I used them instead.

You can make a case for assebler, I can make a case for C. We can both be right. Assembler purely for the sake of it can be a bit hard to understand.

I noticed that Peng Shorn and the guys from Singapore said they wrote in assembler for their processors. That could be personal choice or simply the lack of suitable high-level tools. Last I looked, Dave Otten was still writing in assembler, Derek Hall uses assembler...

There is a certain satisfaction in assembly coding but I don't think I have the mental faculty to keep track of assembly programs any more. Especially on the thrice cursed PIC architecture (go on - bite). Speaking of which, anyone looked at the new PIC24 devices. At last, a real processor from Microchip and their C compiler seems to be a port of GCC. Things are looking up.

MichaelB

  • phpBB Member
  • *****
  • Posts: 70
(No subject)
« Reply #6 on: 22 June, 2006, 04:23:31 PM »
There are lots of advantages to assembly language as well (so I am jumping ship and partly contradicting my earlier post) :-
(1)...There seems to be a huge amount of low level I/O and related activity in a Micromouse software design, which would seem to be time critical.  It can be easier/more efficient/ and more accurate timing by writting it in Assembly rather than C.

(2)...In much of my past C coding work, it has been done with fairly large/medium sized teams, so that some kind of simplistic operating system has been written which controls the exact execution time of things, and what activates when etc.
The scheduling may be simpler in Assembly language, because you don't have to worry about the effect on other things (e.g. Are the C library functions re-entrant).

(3)...

Quote
I noticed that Peng Shorn and the guys from Singapore said they wrote in assembler for their processors.


They are using a DSP processor (digital signal processor).  It is still fairly common for DSP programs to be written in assembly language (I think), because traditionally, C did not cope very well with the powerful resources on a DSP, and assembly language allows you to get the full performance out of the DSP, which you should need (because otherwise, why are you using a DSP rather than a cheap/simple processor, if you don't need its power ?).

gorgon

  • phpBB Member
  • *****
  • Posts: 11
Re: What programming Language do you use?
« Reply #7 on: 06 September, 2009, 09:21:31 PM »
Being an old assembler geek for 30+ years myself, and starting to program in C resently, I can see several reasons for both languages. If you are using the same processor family/ variants, the portability issue is not that important. If you have designed a set of routines in one assembler there is a limited amount of work to port it to a new device, even another brand. Migrating from 8 to 32 bit is another problem, where C is a possible solution.

Anyway, you can't beat assembler dealing with hardware, and I think most C programs made, have some inline assembler code hidden in the deep, at least if they are embedded.

One thing I'm a bit confused about is the use of dynamic allocation of heap memory on an embedded/ robotic platform. Personally I can't see the need for it, and it cause lots of problems if you are not careful.

Could you tell me if memory allocation is common in the programs used in robots?

TOK  ;)

peteh

  • Administrator
  • phpBB Senior member
  • *****
  • Posts: 512
Re: What programming Language do you use?
« Reply #8 on: 07 September, 2009, 11:36:37 PM »
I disagree about the hardware thing and assembly.
First, I don't think you need to use assembler to talk to the hardware.
Second, It is not automatically 'better' to use assembler to talk to the hardware.
Third, there are plenty of embedded C programs out there that have no assembler code hidden away in them.


There is no need to worry about the heap in an embedded program if you simply avoid those parts of the library that make use of the heap. That means don't use calloc() or malloc(). I believe that means don't use printf().

MISRA discourage it as well.

adwin

  • Newbie
  • Posts: 8
Re: What programming Language do you use?
« Reply #9 on: 10 September, 2009, 05:18:15 AM »
Quote from: "peteh"
I believe that means don't use printf().
I have been using the printf's to print on Nokia 3310 LCD with avr-gcc compiler.  
I never knew it could be harmful.

peteh

  • Administrator
  • phpBB Senior member
  • *****
  • Posts: 512
Re: What programming Language do you use?
« Reply #10 on: 10 September, 2009, 07:06:34 AM »
There is nothing intrinsically wrong with using printf. It is a very convenient way to format output. It can, however, add a lot of code to your program and may use dynamically allocated memory at run time.

Many compilers have a reduced version of printf. Leaving out support for floats is a common option.

williamparkar

  • Newbie
  • Posts: 3
Re: What programming Language do you use?
« Reply #11 on: 23 November, 2009, 03:30:57 AM »
Hello andynxn,
I have used C language the most when there were no C++ available, C was the language
which was not user friendly. Then JAVA came into market and i was attracted to it because
it was able to give the graphical outputs and also we  were able to create web applications
by the use of JavaScript.Currently i am using all the web developing applications like asp.net
and php, this two languages are very user friendly and coding is reduced so there is very less
errors when we run the program.

Micromouseonline Forum

Re: What programming Language do you use?
« Reply #11 on: 23 November, 2009, 03:30:57 AM »