我使用的是ARM/Cortex-A8处理器平台。
我有一个简单的函数,我必须将两个指针传递给函数。这些指针稍后会在只有我的内联汇编代码的函数中使用。此计划只是为了实现性能。
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);
}
谢谢
最佳答案
假设您使用普通的 ARM ABI,这两个参数将在 R0
和 R1
中传递。下面是一个简单示例,展示了如何将字节从输入缓冲区复制到输出缓冲区(gcc 语法):
.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
关于c - 内联汇编: Passing pointers to a function and using it in that function in assembly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3678452/