我需要编写
的C代码DDRB &= ~pins;
内联汇编(AVR)。我之前从未使用过它。我的尝试:
register uint8_t t1, t2; // temporary registers
__asm__ volatile (
"in %[t1], %[w1_ddr]" "\n\t"
"mov %[t2], %[pins]" "\n\t"
"com %[t2]" "\n\t"
"and %[t1], %[t2]" "\n\t"
"out %[w1_ddr], %[t1]" "\n\t"
: [t1] "+r" (t1),
[t2] "+r" (t2),
[w1_ddr] "+I" (_SFR_IO_ADDR(DDRB))
: [pins] "r" (pins)
);
gcc
出现以下错误lvalue required in asm statement
。我做错了什么?
答案 0 :(得分:1)
AVR中的“I”约束表示操作数是常量。因此它不能是“+”,即输入 - 输出。明白输入,如下:
register uint8_t t1, t2; // temporary registers
__asm__ volatile (
"in %[t1], %[w1_ddr]" "\n\t"
"mov %[t2], %[pins]" "\n\t"
"com %[t2]" "\n\t"
"and %[t1], %[t2]" "\n\t"
"out %[w1_ddr], %[t1]" "\n\t"
: [t1] "+r" (t1),
[t2] "+r" (t2)
: [w1_ddr] "I" (_SFR_IO_ADDR(DDRB)),
[pins] "r" (pins)
);