Gcc内联ASM输入变量

时间:2013-10-14 20:39:43

标签: c gcc assembly inline-assembly

我有这段代码:

void  geninterrupt (int x) {
    __asm__(
    "movb x, %al \n"
        "movb %al, genint+1 \n"
        "jmp genint \n"
    "genint: \n"
        "int $0 \n"
    );
}

如何让movb使用geninterrupt()的参数?

1 个答案:

答案 0 :(得分:2)

您需要正确使用约束字段:

void  geninterrupt (int x) {
  __asm__("  movb %[x], %%al \n"
          "  movb %%al, genint+1 \n"
          "  jmp genint \n"
          "genint: \n"
          "  int $0 \n"
         : /* no outputs */
         : [x] "m" (x) /* use x as input */
         : "al" /* clobbers %al */
         );
}

Here's a good how-to about GCC inline assemblylink to the relevant GCC documentation

编辑:因为您的GCC似乎无法处理标记的操作数