我有以下代码:

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

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

最佳答案

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

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似乎无法处理标记的操作数

10-07 15:33