it is possible to write assembly, but that c/c++ codes tend to be more readable and maintainable.
in terms of savings, you can possibly write / make smaller binaries with assembly. But for my purpose, as I'd rather simply get a chip with a more comfortable margin of sram and flash, I'd make do with c/c++ codes.
In addition, assembly tend to be far more verbose (at least in terms of lines of code) as compared to c/c++ codes.
e.g. a function like
Code: Select all
int plus(int a, int b) { return a + b; }
can compile into a 'whole page' of assembly e.g. with gcc -S for a practical one liner.
for inline assembly, normally on mcus e.g. stm32, it is used for 'special' situations, e.g. like
Code: Select all
asm("wfi"); // wait for interrupt
asm("wfe"); // wait for event
asm("dmb"); // data memory barrier
asm("dsb"); //data synchronization barrier
asm("isb"); //Instruction Synchronization Barrier
otherwise, much of other codes is much easier to read and maintain in simple c/c++ codes.
For the above, there are probably intrinsics for the same rather than specifying like asm("wfi"), but that I tend to use that for 'convenience'.
https://developer.arm.com/documentation ... -functions
In terms of speed optimization, there is very little to gain on a microcontroller. I've tried some arm assembly coding, it turns out gcc's -O2 along with some other optimization features can make codes that run faster than what you naively try to optimize.
so the only reason to write assembly on an mcu is when you are trying to save the use of every byte, such as is with a processor say with 1k sram and 4k flash, most stm32 are far more generous than that. And that I'd rather go for a chip that has more generous sram and flash, then try to squeeze in those 1k sram and 4k flash constraints.
It often don't cost very much more.
And that you would need to pick up ARM assembly if you really want to learn that. simply google ARM assembly and there'd be lots of hits.
you can nevertheless learn some of that and learn to read some codes during debug, after a while many of the generated codes are literal repeats.