views:

99

answers:

1

Guys,

I'm using ARM/Cortex-A8 processor platform.

I have a simple function where I have to pass two pointers to a function. These pointers are later used in that function which has only my inline assembly code This plan is only to achieve performance.

function(unsigned char *input, unsigned char *output)
{
     // What are the assembly instructions to use these two pointers here?
     // I will inline the assembly instructions here
}

main()
{
    unsigned char input[1000], output[1000];

    function(input, output);
}

Thanks

+3  A: 

Assuming you're using a normal ARM ABI, those two parameters will be passed in R0 and R1. Here is a quick example showing how to copy the bytes from the input buffer to the output buffer (gcc syntax):

.text
.globl _function

_function:
   mov  r2, #0        // initialize loop counter
loop:
   ldrb r3, [r0, r2]  // load r3 with input[r2]
   strb r3, [r1, r2]  // store r3 to output[r2]
   add  r2, r2, #1    // increment loop counter
   cmp  r2, #1000     // test loop counter
   bne  loop
   mov  pc, lr
Carl Norum
Thanks Carl, can you tell me from where did you learn to write assembly code for ARM processors, any books or resources you can suggest will be very helpful.
vikramtheone
Carl Norum
As an aside - I like to recommend against inline assembly whenever possible. Write a real assembly routine in a real assembly file - it will make maintenance and porting a lot easier.
Carl Norum
What should the layout be for a real assembly file? I don't know much about assembly, thats why I thought of somehow managing with inline assembly. Can you write the above written code by you, as if it were written in a .s file, as a function(with a name), and call it from the main() function? My colleague told me about Code, Data segments and so on, can you kindly include all that in your example? I will use your files as models and then start learning more about them. The hard parts for me is about Code Data segments and calling the functions written in assembly from functions written in C.
vikramtheone
@vikramtheone, ok I made some edits. It's gcc syntax, so if you use a different assembler, you will need some different directives. You call the function just as you would normally. Make sure to have a function prototype somewhere so the compiler knows what's going on, though. Once you have the C file and the assembly file translated into object files, you can link them together, and presto!
Carl Norum
Carl, that was pretty simple thank you! I could compile and assemble and use the functions as per my need. One problem has now cropped up during assembling. From using simple ARM instructions I have now included ARM NEON instructions, in my assembly function, for example vmull.f32 and so on, for which I get errors from the assembler. The errors look like this - Error: bad instruction 'vmull.f32...'. Whats going wrong over here? When I used ARM intrinsics I included a header file called arm_neon.h, do I need to do something similar with another header file for the assembler now? Fingers crossed
vikramtheone
@vikramtheone, you probably need to pass the right flags to the assembler for it to know about the NEON instructions. Probably the mode you're using doesn't include them. You'll have to read the assembler documention to figure that out.
Carl Norum
Hey Carl, I have gotten into problems with some compilation of code for my NEON, can you kindly take a look at my latest question (Asked on 28-Sep-2010). I find that its a bug in the gcc compiler, I'm not able to proceed further.
vikramtheone