我有这段代码:
void geninterrupt (int x) {
__asm__(
"movb x, %al \n"
"movb %al, genint+1 \n"
"jmp genint \n"
"genint: \n"
"int $0 \n"
);
}
如何让movb
使用geninterrupt()
的参数?
答案 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 assembly和link to the relevant GCC documentation。
编辑:因为您的GCC似乎无法处理标记的操作数