C vs Assembly language

c vs assembly

In this article, I am trying to explain some criteria of language selection and describe the difference between the c and assembly language.

When we start a project then language selection is big miles stone. We select the language as per our requirements.

Generally, people select language on the basis of the following points.

  • Portability: Portability is the most important factor in language selection. If the source code is not portable then we have to pay a lot of time.
  • Maintainability: Language should be easy to understand otherwise it will take a huge amount time for small changes.
  • Availability: Compiler and IDE should be easily available in the market and most important thing is that it should be cheap.
  • Efficiency: Language has a good efficiency and bug rate should be less.
  • Development time: Take less amount of time to develop the project.

 

If you want to learn more about the c language, here 10 Free days (up to 200 minutes) C video course for you.

Your free trial is waiting

 

C VS ASSEMBLY

Every language has own importance, we cannot say any language good or bad.In my project, we had used only some lines of assembly code beside it all remaining code we had written in C.

There are following points which describe the difference between C and Assembly.

  • The c language provides portability and does not depend on the specific platform. It is the biggest advantage of C and this property make people helpless to use C.The code which was written in c could be easily reused on a different platform, beside it Assembly does not provide the portability and source code specific to a processor because assembly instruction depends on the processor architecture.
  • Software which has written in assembly perform well as compared to C. Now’s days C compiler generate more optimize assembly code. C compilers generally do better optimizations than you can sustain for hours and days.
  • In general, we cannot say compiler-generated assembly code always better, because when human writes a software in assembly then he thinks a lot of scenarios specific to the requirement and processor which did not handle by the compiler.
  • In case of micro-controller IDE generate an assembly code (startup code) to initialize the stack, heap, and NVIC. And further, it is hard to maintain Assembly code. So when stack and heap have initialized we used to call a C function to initialize different system clocks.
  • I believe API which has written in assembly would be fast. That is the biggest reason to write memset () and memcpy () routine in assembly.
  • I believed executable generated by assembly language have smaller size compare to c language but not always true.

Your opinion matters

Here, I have tried to explain the difference between the c and assembly language but I would like to know your opinion on assembly and c language, so please don’t forget to write a comment in the comment box.



2 comments

  1. Amlendra, I’d like to add to your article here, by pointing out a few additional things.

    Many of today’s compilers write better assembly code than can be done by hand since the code-generating compiler backends are generally written by the same group as the design of the CPU core. They understand issues like the pipelining of instructions and cache-structure far better than us mere mortals. This is the reason why compiler-optimised code can often be smaller than hand-assembled code.

    C helps programmers focus on the structure of the code rather than the low-level demands of the CPU. They can organise code into components, such as functions and files and they have ways of managing the complexity of a project; without thinking about the nitty gritty of issues such as how function calls work.

    Since C is a portable language, code can be organised into general purpose libraries which can be used on any platform, often with no modification. It is a great weapon against ‘reinventing the wheel’.

    C has most of the power of assembly language, but this comes at the price of ‘safety’. Organisations such as MISRA exist to guide C programmers in helping them not making dangerous assumptions about the language. After all, none of us want our car engines to explode unexpectedly.

Leave a Reply