Hi,
I have been working on getting a C function with inline assembler to run, but with very little success.
It is very difficult to understand the syntax for this type of code but I think I finally understand at least part of it. However if I try to use indirect (indexed) addressing in my assembler code, strange things happen.
If I use a static declared variable for the address it works, but if I use a local variable for the address the address is extracted from the SP (and I guess that is correct) but it is completely wrong.
This example is working:
UINT32_t os_sub(UINT32_t tmp0, UINT32_t tmp1, UINT32_t tmp2, UINT32_t tmp3)
{
UINT32_t asm_out;
static UINT32_t tmp3_loc = 0x1000;
static UINT32_t* tmp3_adr;
tmp3_adr = &tmp3_loc;
asm volatile
(
"nop\n\t"
"MOV %1,%1\n\t"
"ADD %0,%1,%2\n\t"
"ADD %0,%0,%3\n\t"
"MOV %4,%4\n\t"
"LDR %4,[%4]\n\t"
"ADD %0,%0,%4\n\t"
"nop\n\t"
: "=r"(asm_out) /* related to %0 */
: "r"(tmp0), /* related to %1 */
"r"(tmp1), /* related to %2 */
"r"(tmp2), /* related to %3 */
"r"(tmp3_adr) /* related to %4 */
);
/* Needed for halting debug before return */
asm_out += 0x10000000;
return(asm_out);
}
And this is not:
UINT32_t os_sub(UINT32_t tmp0, UINT32_t tmp1, UINT32_t tmp2, UINT32_t tmp3)
{
UINT32_t asm_out;
UINT32_t tmp3_loc = 0x1000;
UINT32_t* tmp3_adr;
tmp3_adr = &tmp3_loc;
asm volatile
(
"nop\n\t"
"MOV %1,%1\n\t"
"ADD %0,%1,%2\n\t"
"ADD %0,%0,%3\n\t"
"MOV %4,%4\n\t"
"LDR %4,[%4]\n\t"
"ADD %0,%0,%4\n\t"
"nop\n\t"
: "=r"(asm_out) /* related to %0 */
: "r"(tmp0), /* related to %1 */
"r"(tmp1), /* related to %2 */
"r"(tmp2), /* related to %3 */
"r"(tmp3_adr) /* related to %4 */
);
/* Needed for halting debug before return */
asm_out += 0x10000000;
return(asm_out);
}
Am I doing something wrong or?
Regards