Hello again.
As I am very interested in learning ARM architecture, I would have few questions regarding assembly programming. Questions refer primarily to programming Cortex-M processors, because they are the only one which I am using (at least for now).
So... Do you program in C or assembly and why that? How do you suggest to start learning assembly programming? Do you think that the gain of execution time is big enough to justify time spent for assembly programming instead of C programming (with full optimization). Because in my case, processing time is quite important. Do you maybe only use intrinsics in special cases? Or inline/embedded assembly?
Every hint is very welcome and appreciated. Thank you in advance.
Regards,
Matic
Hi,
I think you say about not C++ but C.
If it is correct, I don't feel there would be so big differences between C and the assembler.
I think they are almost the same.
Also, the processing time would be almost the same.
Bt the way, in the Cortex-M world, almost all things are describable by C.
I cannot find big advantages to use the assembler.
Mr. Jens Bauer might have another opinion because he like the assembler very much. I can also respect his works in this community.
Best regards,
Yasuhiko Koumoto.
Thank you Mr. Koumoto. Yes, I am programming in C, not C++.
For 99.99% of new code start with C, and just take care how you write it for the bits where performance matters. In general if you write C the same way you write assembler then the compiler will usually win on performance, and you get all of the benefits of C over assembler (readability, portability, development speed).
Starting out with assembler is just going to give you a very large amount of development pain, because it's just so much slower to write, debug, review, and maintain. It is always possible to add in small amounts of assembler in to a C program later for any performance hotspots if you really need to (but even then I would start by trying to optimize the C code as C code first) ...
HTH, Pete
I do totally agree with peterharris.
The most efficient way I found is to write C code with intrinsics for all non-C operations (parallel arithmetic, saturation, bit/bytes reversing ...).
Also, be aware that C code final execution efficiency depends on you compiler choice and on the optimization options you use.
From my point of view, you may beat a compiler writing assembly but it would probably take you 10 times the effort.
A very simple process that you can use to be sure that your C code is efficient is to look at compiler output (disassembly listing) and to improve your C to reach better performance.
The only exception I have in mind is for Embedded Operating Systems where you need to switch contextes and directly manipulate special registers ! But this kind of code doesn't change every morning !!
Of course, I explained this in details on my blog because I went through the same questions than you do !
> A very simple process that you can use to be sure that your C code is efficient is to look at compiler output (disassembly listing) and to improve your C to reach better performance.
A usefull tool for such stuff: Compiler Explorer
This tool seems to work only with GCC compilers. Even with full optimization, I never managed to get comparable code efficiency (compared to Keil or IAR compilers).
Therefore, from my experience, if someone tries to get the most from its Cortex-M4, they should not go towards GCC.
In addition, all compilers I know allow to generate assembly listing with interlaced C source during standard compilation, you just need to ask nicely !
Here is a nice tutorial for Cortex-A (e.g. Raspberry Pi):It requires to have a working Linux environment (e.g. Debian like OS).
ARM assembler in Raspberry Pi – Chapter 1 | Think In Geek
Regards,Peter
Thanks. I already looked at your blog and it seems very informative. I will definitely go through your posts.