Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

assembly or c which is better for industrial purpose

Status
Not open for further replies.

rahul gaur

Newbie level 1
Joined
Dec 7, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,295
guys,


i have completed a project in assembly.i want to yhe aspects of both c & assembly which is better.please help.
 

hi,

I do not have a lot of experience (solution for industrial purpose), but I never learned assemler, only C. I have a couple of friends which develop a few solutions for industrial purpose, and they both use only C (AVR ICC). They are satisfied with C, and they use assembly code in C only for nop; command.

My oppion, C is better than assembler, but I am not proffesional with embedded systems. Of course, compilers are different, and there you must make chose which is better "translator" from .C to .hex.
 

In my view....it is the choice that one has to make based on application....assembly generally used to have small memory space and high degree of optimization is required in the codes.....but C is more generic and codes with C may or may not get optimized bcz of the interperetor and compliers which converts C code in to assembly language....
 

In the days when microcontrollers only had a few K of program memory and a few bytes of RAM assembly language programming skills were critical. That was over 20 years ago. These days it is cheaper to buy a more powerful microcontroller and program it in a high level language such a C or C++ rather than paying an expensive programmer to spend large amounts of time attempting to write a complete system in assembly language (possibly sections of very time critical code may be written in assembly language). In addition modern optimising C compilers can generate very efficient code and are usually supplied with libraries of functions to assist with operations from controlling IO devices thru to performing FFTs.
I would therefore recommend you to concentrate on C. It may be worth while spending a few days working with assembly language to get an appreciation of it.
 

I think that for general purpose programming C is better because it allows for faster coding and more easily understandable code.

On the other hand if application is industrial, especially when high reliability is needed ASM is better. This is because by coding in C you can NEVER be sure what does the compiler do. In asm on the other hand microcontroller will NEVER do something which you didn't explicitly order it to do.

I think ASM should be used anywhere, where computing speed, execution timing, reliability, real time operation, reaction time etc are critical factors.

Other than that coding in ASM takes much longer than coding the same functionality in C, so use of ASM has to be justified, especially when project is commercial and software coding time translates directly into money.
 

poorchava said:
by coding in C you can NEVER be sure what does the compiler do.

This is why disassembly windows exist!
We are just too lazy sometimes to check those out! :smile:
 

This is true, but it doesn't make sense to first write code in C and then examine whole assembly output line by line to check if compiler didn't mess something up.
 

poorchava said:
This is true, but it doesn't make sense to first write code in C and then examine whole assembly output line by line to check if compiler didn't mess something up.

Of course! Someone could do that in time critical tasks, or code reduction cases. Furthermore if you optimize a peace of code through this procedure, then you remember each case separately. For example for my compiler, it is more effective to access a double array element through pointer inside two foor loops, than directly with the loop counters. Or it is quicker to use a switch-case instead of using a function pointer. So only in time critical situations, I use the best method from optimization point of view. In another part of the code where I don't care about execution time, of course I will access array elements directly, I am not a masochist to declare pointers all the time and mess the easy code observation!
 

My oppion, C is better than assembler, but I am not proffesional with embedded systems.
Neither am I... it just depends on how you define "best".

If with "best" you mean most efficient / compact / fastest possible code, assembly is the way to go. Assembly can do everything C does (because C is translated into assembly at some point), possibly in a smaller space or higher speed.

If with "best" you mean easiest to produce, maintain, portable / readable code etc, then C is the way to go.

For most applications time-to-market & maintainable code is what matters, not squeezing last % of performance out of a part. Even if there is a bottleneck, it's usually enough to include a small piece of assembly for that time-critical section. For everything else, C compilers are usually pretty good at producing optimized code (or at least good enough!), and spending loads of time to produce 'hyper-optimized' assembly code makes no sense business-wise.

That said, it isn't a bad thing for a programmer to understand what happens at the lowest level. So if you've never done anything in assembly, it may make you a better programmer if you do sometime. Especially if your day job involves working with low-level code like in industrial / embedded systems.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top