avr内联汇编程序错误:不可能的约束

时间:2014-05-04 13:13:38

标签: c assembly inline-assembly avr

#include <avr/io.h>

int main(void){

    asm volatile("ldi r16, %0\n\t"
                 "out %1, r16\n\t"
                 "ldi r16, %0\n\t"
                 "out %2, r16\n\t"::"M" (0xff),"I" (_SFR_IO_ADDR(DDRB)),"I" (_SFR_IO_ADDR(PORTB)));

    while(1) {
        asm volatile("cbi %0, %1\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "nop\n\t"
                     "sbi %0, %1\n\t"::"I" (SFR_IO_ADDR(PORTB)), "M" (0xff));
    }
}

编译时:错误:不可能的约束 指针设置为asm语句位置:11-9(asm volatile(&#34; cbi%0,%1 \ n \ t&#34;)

但为什么?

1 个答案:

答案 0 :(得分:1)

您缺少SFR_IO_ADDR(PORTB)上的前导下划线,因此它被编译为对返回整数的外部函数的调用。如果您启用了警告,则会看到:warning: implicit declaration of function 'SFR_IO_ADDR'