我需要在此代码中更改两个数组元素。就像我在C中做str[0] = astr[1] = b一样。它是C代码,Linux中的内联汇编程序。

char str[] = "9999\n";
int a = 1;
inb b = 1;
asm volatile (
    //replace 1st element of str with a here
    //replace 2st element of str with b here
    : "=r" (str)
    : "r" (a), "r" (b), "r" (str)
    : );

最佳答案

我了解您想做str[0] = a; std[1] = b;

你可以做

__asm__ ("movb %0, (%1)\n\tmovb %2, 1(%1)" : : "r" ((char)a), "r" (str), "r" ((char)b) : "m"(*str));


这当然是AT&T样式的装配。

关于c - 更改内联汇编中的数组元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43229087/

10-11 22:39
查看更多