We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I want add some inline assembler in my c-code: but at the moment I get some errors.
unsigned int sum=0; __asm ("adds %0, %1, %1, lsl #16 \n\ addcs %0, %0, #0x10000" : "=r" (sum) : "r" (sum) : "cc"); return (~sum) >> 16;
The error messages for this line (addcs %0, %0, #0x10000") are "expected an expression" and "Missing operand". Do Keil know the assembler code "addcs"?
best regards Tim
I somehow forgot to mention what compiler.
There are at least three possible ARM compilers, and there is no single standard for inlining assembler.
On the other hand - exactly why do you want to inline assembler? You are better off by creating an assembler file and placing the full function there.
Some compilers will even run the peephole optimizer over the combined assembler/C function, so even when you write explicit assembler instructions, you may end up with a function that has your instructions replaced with a different sequence. Some compilers are very bad at understanding what you do in inline assembler, so you may get a huge number of registers that are saved/restored around your inlined code.
In the end, you will create an incompatible C file that you will not really know the end result of.
I'm working with the uvision mdk keil compiler.
On the other hand - exactly why do you want to inline assembler?
It's the checksum calculation for ip pkts - so I hope to get a faster calculation using assembler instead of c-code.