Tekkzz
Tekkzz

Reputation: 638

avr inline assembler error: impossible constraint

#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));
    }
}

At compilation: error: impossible constraint the pointer is set to the asm statement position: 11-9 (asm volatile("cbi %0, %1\n\t")

But why?

Upvotes: 0

Views: 496

Answers (1)

Jester
Jester

Reputation: 58762

You are missing the leading underscore on SFR_IO_ADDR(PORTB) so it gets compiled as a call to an external function returning an integer. If you had enabled warnings you would have seen this: warning: implicit declaration of function 'SFR_IO_ADDR'

Upvotes: 1

Related Questions