Inline Assembly: Passing pointers to a function and using it in that function in assembly
-
01-10-2019 - |
Question
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
Solution
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow