Software > Software

C vs. ASM

(1/2) > >>

stopgo:
If I really want to grok robotics and create the best machines, should I code in ASM or C?  Does the answer vary from situation to situation?

JesseWelling:
C is close to the hardware when it you need it to be, yet you can work at pretty high level if you need to. You just generally need to make the hierarchy yourself...

So I don't think you are going to learn much from assembly programing that you wouldn't learn from programing in C. Except to be more appreciative of compiler writers.... :P

snow:
C is good for this microcontrollers that we have today - a lot of flash, couple of hardware timers etc.

You use ASM if you really want to squezze most of you microcontroller or if you do some time criticall stuff... and it is sometimes good for debugging. But ASM is different for different MCU, whereas C is basicly the same everywhere. And sometimes you will swear about simple stuff like comparing two values and doing something based on that comparison in ASM... which is a piece of cake in C.


So my advice is to learn C and spend other time on learining about electronics, motors, sensors, etc.

stopgo:
Thanks for the responses!  I'm fluent in C.  My ASM skill is basically read-only, for the moment.  Having written a compiler, I can appreciate JesseWelling's point - I'll probably get equal- or better-quality machine code out of a compiler than what I can write myself in 5-10x the time.

I guess I was thinking that making myself code in ASM would really drive the nature of my mcu into me.  But from what I've seen so far, JesseWelling sounds right:  the C code actually looks like it can get pretty close to the ASM anyway.  And so snow's probably right - my time would be much better spent working on other things.  The issue looks settled.  Thanks guys!

Now a related question: anyone know how good gcc-avr's optimizations are, relative to those of other AVR compilers?

JesseWelling:
I haven't done any benchmarking but I can tell you that the -Os optimization really works... I can go from 49k with an -O3 optimization to a 36k with -s on one of my projects. As for speed... dunno... but I think gcc uses intermediate code between the C and the resulting executable, and runs optimizations on that, I think it should be on par with regular gcc.

Navigation

[0] Message Index

[#] Next page

Go to full version