无法使用字符串变量中的指令执行内联汇编程序

Can't execute inline assembler with the instructions in a string variable

我正在尝试执行内联汇编,将一个变量作为输入

void main(void)
{
    char a[20] = "mov edx, 88";

    asm("%[a]" : : [a]"r"(a));
}

但是:

gcc a.c -masm=intel
Error: no such instruction: `eax'

我怎样才能使这个工作?

指令必须是字符串文字的形式(实际写入的字符串,char数组的名称是一个指针btw)。 除此之外,您了解了总体思路:)

#include <stdio.h>

int main(int argc, char ** argv){
char a[20] = "nice try:)";
char * dst;

asm("mov %[dst], %[src]\n\t"
    : [dst]"=r" (dst) : [src]"r"(a));

printf("%s\n", dst);
return 0;
}

和有用的link: https://dmalcolm.fedorapeople.org/gcc/2015-08-31/rst-experiment/how-to-use-inline-assembly-language-in-c-code.html