2

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

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

8 Comments

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, I have been working with ARM for a long time. I learned the assembly from reading disassembled code and looking up the instructions in the ARM Architecture Reference Manual (available as HTML & PDF at arm.com).
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.
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, 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!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.