impossible constraint in asm while compilation

此生再无相见时 提交于 2019-12-24 06:34:13

问题


In my Atmel ASF project, I am trying to build following inline asm code. However I am getting impossible constraint while compilation.

Compiler points to this line __asm__ __volatile__, am I missing anything?

#define OUTPORT PORTD
#define OUTBIT 3      // PD.3   
uint8_t rport ,rbits;
uint8_t *buf = message;
asm volatile(   "in     __tmp_reg__, __SREG__             \n\t" // 1  Save SREG for later
                "cli                                      \n\t" // 1  Clear interrupts
                "in     %[rport], %[port]                 \n\t" // 1  Move PORTB adress to rport

                : //Outputs
                [rport] "=&r" (rport)

                : //Inputs
                [port]    "I" (_SFR_IO_ADDR(OUTPORT))     // Adress to port register, 6-bit positive constant

                : //Clobber list (compiler must restore)

                "r0"                                       // This is __tmp_reg__
);
  1. What is destroying this build?
  2. I wonder if asm syntax is incorrect? I have been following this manual

回答1:


PORTD, on the ATxmega128A4U, is at address 0x0660, as stated in its datasheet, page 62. The port is therefore not accessible to the in instruction. You should use lds instead, with the constraint

[port]  "i" (_SFR_MEM_ADDR(OUTPORT))

Notice the lowercase "i".

Addendum: I just tried compiling the following:

#include <avr/io.h>

void test(void)
{
    uint8_t rport;

    asm volatile(
        "in __tmp_reg__, __SREG__  \n\t"
        "cli                       \n\t"
        "lds %[rport], %[port]     \n\t"
        : [rport] "=&r" (rport)               // output
        : [port]  "i" (_SFR_MEM_ADDR(PORTD))  // input
        : "r0"                                // clobber
    );
}

Using avr-gcc 4.9.2 with the options -mmcu=atxmega128a4u -c I get the correct generated code and no warnings, even with -Wall -Wextra.

The "i" constraints is documented to mean an “immediate integer operand”, whereas "I" means “Constant greater than −1, less than 64”.



来源:https://stackoverflow.com/questions/37765720/impossible-constraint-in-asm-while-compilation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!