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

function argument assigne to ARM register in assembly

Note: This was originally posted on 4th September 2009 at http://forums.arm.com

Hello,

I am developing application on OMAP3530-beagleboard using code sourcery tool chain.
I have used assembly function in my C application.Function has 5 argument it's called from another c function.
function like: void  routine(signed char *a, int b, signed char *c, unsigned char *d, unsigned int *e)
                        {
                           asm volatile{

                                             ........assembly syntaxs....

                            
                                    };
                        }
Here, function argument a to d are stored in r0 to r3 but argument e  either go to stack or store into r4 to r12  register as per called function ?
How can i write assembly syntax in my assembly function to get value of argument e in any specific register so I can use in my function correctly?
How can I write assembly syntax so assembly function parameter passing become independent of called function variable usage means I can use this routine function any other application without doing changed inside the assembly syntax to catch parameter value ?


Thanks,
  • Note: This was originally posted on 8th September 2009 at http://forums.arm.com

    The fifth parameter (and all those after it) always goes onto the stack, never r4 or r12.  For more information, see [url="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042c/index.html"]infocenter.arm.com/.../url]

    To access it you can "LDR r4,[sp,#0]", but be sure to have saved the value in r4 before you change it, since it will need to be restored to the previous value when you exit the function.
    I have used fifth argument as following way.
    void routine(signed char *a, int b, signed char *c, unsigned char *d, unsigned int *e)
    {
    asm volatile{
             "PUSH {r4,r5,r6,r7,r8,r9,10,r11,r12}\n\t"
             "LDR r4, [sp, #36]\n\t"
    ........assembly syntaxs...
    .....................................................
             "POP {r4,r5,r6,r7,r8,r9,10,r11,r12}\n\t"
    };
    }
    But here, I didn't get output of as per expected and if I use this function in other application which call only this routine then I am getting result as per expected.

    I am unsure about what you are asking in the last question.  The ARM ABI defines how parameters are passed in the above document, so following it should result in a function that can be safely used from other places.
  • Note: This was originally posted on 10th September 2009 at http://forums.arm.com

    Hello,
    I have checked disassembly of function which call my assembly routine function on QEMU simulator, as per that it's storing variable e value into stack.

    I have not checked code generated by the compiler for my assembly function. How to check the code generated by compiler for assembly function and C functions?

    how to check value passing in e argument is properly restored in r4 or not in assembly routine ?

    I am storing values into e variable address means r4 and routine has ARM NEON instructions.

    Thanks,
  • Note: This was originally posted on 5th September 2009 at http://forums.arm.com

    Here, function argument a to d are stored in r0 to r3 but argument e  either go to stack or store into r4 to r12  register as per called function ?
    How can i write assembly syntax in my assembly function to get value of argument e in any specific register so I can use in my function correctly?
    How can I write assembly syntax so assembly function parameter passing become independent of called function variable usage means I can use this routine function any other application without doing changed inside the assembly syntax to catch parameter value ?


    The fifth parameter (and all those after it) always goes onto the stack, never r4 or r12.  For more information, see [url="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042c/index.html"]http://infocenter.arm.com/help/topic/com.a...042c/index.html[/url]

    To access it you can "LDR r4,[sp,#0]", but be sure to have saved the value in r4 before you change it, since it will need to be restored to the previous value when you exit the function.

    I am unsure about what you are asking in the last question.  The ARM ABI defines how parameters are passed in the above document, so following it should result in a function that can be safely used from other places.
  • Note: This was originally posted on 8th September 2009 at http://forums.arm.com

    Have you checked the disassembly of the code when you call the function to check the compiler has done the right thing?  Have you checked the code generated by the compiler for your assembly function?  The code you've shown looks correct for getting the 'e' pointer into r4, but you haven't explained enough for us to help.  What do you do with r4?  Where are you using it?  etc
  • Note: This was originally posted on 12th September 2009 at http://forums.arm.com

    I have not checked code generated by the compiler for my assembly function. How to check the code generated by compiler for assembly function and C functions?


    The "-S" option will output the assembly for the code that is being compiled.