我正在使用GCC编译器。我想将一些内联指令插入C。使用 __ asm __ 指令成功插入非分支指令,如下所示:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]\n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
但是我无法插入分支/跳转指令。编译出现以下错误:
../test.c:5: error: expected '(' before 'goto'
../test.c:5: error: expected identifier or '*' before 'volatile'
我尝试了以下代码:
unsigned int array[10] = { 0x22, 0x12,0,0,0,0,0,0,0};
int main() {
__asm__ goto volatile (
"jp %l[label]\n"
: /*no output*/
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
: /*no cobblers*/
: label
);
return 0;
label:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]\n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
return 0;
}
您能帮忙更正此代码吗? 问候