This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

在64bit下,C程序可以使用内联汇编吗?

比如:

C函数中:使用asm volatile ("MRC......")之类的。

使用Aarch64 gcc编译时,会报错吗?

best wishes,

Parents
  • 可以,语法和gcc兼容 下面是一个示例

    #include <stdio.h>

    int add(int i, int j)

    {

    int res = 0;

    __asm (

    "ADD %[result], %[input_i], %[input_j]"

    : [result] "=r" (res)

    : [input_i] "r" (i), [input_j] "r" (j)

    );

    return res;

    }

    int main(void)

    {

    int a = 1;

    int b = 2;

    int c = 0;

    c = add(a,b);

    printf("Result of %d + %d = %d\n", a, b, c);

    }

Reply
  • 可以,语法和gcc兼容 下面是一个示例

    #include <stdio.h>

    int add(int i, int j)

    {

    int res = 0;

    __asm (

    "ADD %[result], %[input_i], %[input_j]"

    : [result] "=r" (res)

    : [input_i] "r" (i), [input_j] "r" (j)

    );

    return res;

    }

    int main(void)

    {

    int a = 1;

    int b = 2;

    int c = 0;

    c = add(a,b);

    printf("Result of %d + %d = %d\n", a, b, c);

    }

Children