0

我需要编写 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。我究竟做错了什么?

4

1 回答 1

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)
); 
于 2012-11-21T21:17:12.933 回答