This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

assigning function parameters to registers

I have code (borrowed from another platform )that attempts to optimize by using assembly code.
The function is an addition of arrays and is a C function such as
uint32_t AddNumbers ( uint32_t *p_addResult , uint32_t *p_left , uint32_t *p_right , const uint ARRAY_SIZE)

Can I get pointed to a syntax where the passed variables can be assigned to registers and assembly variables.



uint32_t AddNumbers ( uint32_t *p_addResult , uint32_t *p_left , uint32_t *p_right , const uint ARRAY_SIZE)
{

uint32_t l_counter = ARRAY_SIZE;
uint32_t l_carry = 0;
    uint32_t l_left;
    uint32_t l_right;
 __asm(
       ..
        "ldmia %[lptr]!, {%[left]} \n\t"
        "ldmia %[rptr]!, {%[right]} \n\t"
        "lsrs %[carry], #1 \n\t"
        "adcs %[left], %[right] \n\t"

         ...
        : [dptr] "+l" (p_addResult), [lptr] "+l" (p_left), [rptr] "+l" (p_right), [ctr] "+l" (l_counter), [carry] "+l" (l_carry), [left] "=l" (l_left), [right] "=l" (l_right)
}

I am getting syntax errors for the part above that assigns the C variables to registers and assembly variables.

Thanks

Parents
  • So beautifully explained!
    Thanks !

    I think I've gotten a handle of most of it
    However am trying to wrap my head around some of the pointer to register translation

    FunctionCall( ptr 1 , ptr 2 , ptr 3 , size)

    Now these are mapped to r0, r1 , r2 and r3 right ?

    The first iteration of the loop uses ptr1[0] essentially index 0
    I am unable to establish the point where the association between r0 and the next address (ptr + 1 ) occurs.

    I see the loop condition being updated but where does the transition from use ptr to using ptr+1 occur?

    Thanks!

Reply
  • So beautifully explained!
    Thanks !

    I think I've gotten a handle of most of it
    However am trying to wrap my head around some of the pointer to register translation

    FunctionCall( ptr 1 , ptr 2 , ptr 3 , size)

    Now these are mapped to r0, r1 , r2 and r3 right ?

    The first iteration of the loop uses ptr1[0] essentially index 0
    I am unable to establish the point where the association between r0 and the next address (ptr + 1 ) occurs.

    I see the loop condition being updated but where does the transition from use ptr to using ptr+1 occur?

    Thanks!

Children