Issue
I am trying to do an operation with assembly over an address pointed by a c pointer, now the problem i have is that i can't find the way to pass the pointer to a register and then do my operation in the data then store the value to another output pointer.
here is my code: what am i missing?
void asmfunc(short *pOut, short *pIn) {
asm volatile(
"ldr r0, [in];"
"ldr r1, [out];"
"mov r2, r0;"
"lsr r2, [r2], #1;"
"str r1, [r2];"
:[out] "=m" (pOut)
:[in] "m" (pIn)
);
}
Solution
What you're actually doing there is loading the value from the output pointer, then using the result of the shift as an address to store it to. Note that you also need to tell the compiler that you're using more registers than the ones it knows about and changing values in memory, or eventually subtle bugs will bite you. The equivalent to what I think you're trying to do would be something like this -
void asmfunc(short *pOut, short *pIn) {
asm volatile(
"ldr r3, %[in]\n"
"lsr r3, r3, #1\n"
"str r3, %[out]\n"
:[out] "=m" (*pOut)
:[in] "m" (*pIn)
:"r3", "memory"
);
}
Answered By - Notlikethat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.