内联装配:将指针传递到函数并在汇编中使用该功能
-
01-10-2019 - |
题
我正在使用 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);
}
谢谢
解决方案
假设您使用了普通的ABI,这两个参数将通过 R0
和 R1
. 。这是一个快速示例,显示如何从 input
缓冲区到达 output
缓冲区(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
不隶属于 StackOverflow