编译时在asm中不可能的约束 [英] impossible constraint in asm while compilation

查看:544
本文介绍了编译时在asm中不可能的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Atmel ASF项目中,我正在尝试按照内联asm代码进行构建.但是我在编译时遇到了不可能的约束.

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

编译器指向此行__asm__ __volatile__, 我错过了什么吗?

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. 什么在破坏这个建筑?
  2. 我想知道asm语法是否不正确?我一直在关注本手册

推荐答案

ATxmega128A4U上的PORTD位于地址0x0660,如其 数据表, 第62页.因此,in指令无法访问该端口. 您应该改用lds,并加上约束条件

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))

注意小写的"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
    );
}

使用带有选项-mmcu=atxmega128a4u -c的avr-gcc 4.9.2我得到了 即使使用-Wall -Wextra,也可以更正生成的代码并且没有警告.

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.

"i"约束是 记录 表示立即整数操作数",而"I" 手段 常数大于-1,小于64".

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

这篇关于编译时在asm中不可能的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆