c - 内联汇编: Passing pointers to a function and using it in that function in assembly

标签 c pointers arm inline-assembly cortex-a8

我使用的是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,这两个参数将在 R0R1 中传递。下面是一个简单示例,展示了如何将字节从输入缓冲区复制到输出缓冲区(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/

相关文章:

c - c 中的字计数器不起作用

c# - C# 中的指针及其在应用程序中的使用频率?

assembly - 指令大小是什么意思?

android - 交叉编译到arm时找不到lpthread

c - 如何使用 doxygen 打印我的函数文档字符串?

c - Windows TCP 套接字错误 10045

c - 使指针指向数组的末尾

iphone - ivar 的地址作为参数

c - 错误 : Target CPU does not support ARM mode

c - 为什么在使用 -g 选项编译时没有创建 gdb 符号