i worked thru the manuals, the CARM User's Guide Inline Assembly example:
int AddUp ( int n, int *pTab) { if (n == 0) return(0); __asm { mov r0, #0 ; clear result ldav r2, r0, pTab ; R2=start of table ldav r3, r0, n ; R3=table length lsl r3, r3, #2 lM: sub r3, #4 ldr r1, [r2,r3] add r0, r1 cmp r3, #0 ; end of table ? bgt lM ; loop if not eot } // Return Value in R0 }
First i had to replace:
lsl r3, r3, #2
by mov r3,r3,lsl #2 Second there's a warning C180 not every path returns a value. The question is how to tell CARM that return value is in R0
Disable W180 around these kind of functions:
#pragma warning disable=180 int AddUp (int n, int *pTab) { if (n == 0) return(0); __asm { mov r0, #0 ; clear result ldav r2, r0, pTab ; R2=start of table ldav r3, r0, n ; R3=table length lsl r3, r3, #2 lM: sub r3, #4 ldr r1, [r2,r3] add r0, r1 cmp r3, #0 ; end of table ? bgt lM ; loop if not eot } // Return Value in R0 } //--Enable W180 again ! #pragma warning enable=180 int vTest (void) { int z; z = 1; }
In practice, why not just write it as an assembler function?
That is a matter of taste, I personally prefer to have the prototypes in an .h file so things are kept consistent. Assembly language interfaces are more error prone...
Whether the prototype is in a .h file or elsewhere is irrelevant to the question of whether a function consisting of nothing but assembly code should be put into an assembler source file or as inline assembly into a C file.
Assembly language interfaces are more error prone...
So what? Mind you: there is an assembly language interface between an inline assembly fragment and the C code around it.
Hello to everyone, thanks for reply. In practice, why not just write it as an assembler function? I'am i a test phase, just want to see what are advantages and disadvantages about placing ASM-code in a separated *.S-file or using the INLINE-ASSEMBLER.
So I tested the original example from the CARM-Manual and stumbled over warning C180. I expected there would be a general solution how to tell CARM that return value is in R0. Just suppresing a warning is not really satisfying
Remember that the warning comes from the 'C' Compiler.
The 'C' Compiler does not understand Assembler - so it doesn't know that you have provided a return value in R0!
what is the difference between assembler and inline assembler?
"what is the difference between assembler and inline assembler?"
Inline assembler is just a section of assembler source that's "buried" within 'C' source.