Microchip
直播中

康沧鹤

7年用户 171经验值
私信 关注
[问答]

MPLAB XC8 ASPIC18宏中出错的真正原因是什么?

在汇编程序中,宏中有一些奇怪的问题。当我使用宏编译器说“错误(876)语法错误”时,当宏体直接写入代码时,没有错误。这可能是因为我在宏中使用3级宏吗?那么错误的真正原因是什么呢?谁知道呢?最好的问候,幼珍。

以上来自于百度翻译


      以下为原文

    Hello
Have some strange trouble in assembler source, in macro. When i use macros compiler says "error(876) syntax error", when write the macro body direct to code, there is no error. May be this happens cause i use 3 level of macro in macro?

movfl macro freg,lit
         movlw lit
         movwf freg
        endm
;------------------------------------------------------------------------------
movfl16 macro freg,lit
         movfl freg,Low(lit)
         movfl freg+1,High(lit)
        endm
;------------------------------------------------------------------------------
movfl32 macro freg,lit
         movfl16 freg,(lit & 0x0000FFFF)
         movfl freg+2,(lit >> 0x10) & 0xFF
         movfl freg+3,(lit >> 0x18)& 0xFF
        endm
;------------------------------------------------------------------------------
_func:
    movfl16 ax, (0x4503114F & 0x0000FFFF) // this 3 lines works fine
    movfl ax+2,(0x4503114F >> 0x10) & 0xFF
    movfl ax+3,(0x4503114F >> 0x18)& 0xFF

    movfl32 bx, 0x4503114F // this macro cause an error

So whats the real reason of error? Who knows?

Best regards, Eugene.

回帖(2)

陈鲜孰

2019-7-24 11:04:24
运算符在ASPIC/ASPIC18宏中具有特殊含义。它执行与C函数中类似于π*令牌粘贴操作符的AgMutoTraceTunes。因此:MOVFL16FRG,(LAMP和AMP;0x00,FFFFF)当被调用:MOVF32 32 HASH,0x45031 14F//这个宏引起错误:MOVFL16AX,(0x45031 14F0x00)FFFF等等,其他的行中宏:如果在XC8手册中看到宏指令和ASPIC操作符表。

以上来自于百度翻译


      以下为原文

    The & operator has a special meaning within ASPIC/ASPIC18 macros.  Its performs argument concatenation similar to the ## token pasting operator in a C function-like #define.
 
Therefore:
  movfl16 freg,(lit & 0x0000FFFF)
when invoked by:
movfl32 _hash, 0x4503114F // this macro cause an error
does:
 movfl16 ax, (0x4503114F0x0000FFFF)
and so forth for the other lines in the macro if it ever got that far.
 
Try:
movfl32 macro freg,lit
  movfl16 freg,(lit and 0x0000FFFF)
         movfl freg+2,(lit >> 0x10) and 0xFF
         movfl freg+3,(lit >> 0x18)and 0xFF
        endmSee the macro directive and the table of ASPIC operators in the XC8 manual.
 
举报

朱红艳

2019-7-24 11:16:06
谢谢。我忘了这个……我在XC8用户指南中看到关于它的注释,现在我记得他们推荐使用&&代替……感谢您记住这一点,因为我完全忘记了,并且3次重读了所有关于宏的内容,但是这个注释是之前写的,这样我就再也看不见了…

以上来自于百度翻译


      以下为原文

    thank you.
i forgot about this...i see remark about that in the XC8 user guide, and as i now remember they recommends to use && instead...thank you for remembering about that, cause i absolutely forgot about that, and 3 times reread all about macroses, but that remark was written previously, thus i did not see it again...
举报

更多回帖

发帖
×
20
完善资料,
赚取积分