AVR 汇编 - 在宏中调用宏 (Arduino Uno)

问题描述 投票:0回答:2

我正在学习在 Arduino Uno 上进行 AVR 组装。我在编写程序时遇到编译器错误,看来我误解了宏的正确实现。我试图调用一个由其他宏列表组成的宏,但我不断收到编译错误,暗示编译器不理解或识别该宏。例如:

Within tftMain.s:

#include "avr/io.h"
#include "tftVars.s"
#define __SFR_OFFSET 0

.global tft_reset

tft_reset: 
    SET_WRITE_DIR
    CTL_INIT
    CS_IDLE
    RD_IDLE
    WR_IDLE
    RESET_IDLE
    WRITE_CMD
    RET
Within tftVars.s:

.macro PIN_HIGH port, pin ; (port, pin)
    SBI @0, @1
.endm 

.macro CS_IDLE         
    PIN_HIGH CS_PORT CS_PIN 
.endm

.macro SET_WRITE_DIR
    IN R16, DDRB 
    OR R16, BMASK 
    IN R17, DDRD 
    OR R17, DMASK
    OUT DDRB, R16 
    OUT DDRD, R17
.endm

.macro CTL_INIT 
    RD_OUTPUT
    WR_OUTPUT
    CD_OUTPUT
    CS_OUTPUT
    RESET_OUTPUT
.endm

... 

因此,如代码中所示,我有一个文件

tftMain.s
,其中包含文件
tftVars.s
。编译器错误如下所示:

src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:31: Error: bad expression
...

对于调用宏的每一行都会重复此操作。我觉得我的问题归结为格式化 - 我做错了什么?

assembly arduino avr gnu-assembler
2个回答
0
投票

宏内

SET_WRITE_DIR
:

.macro SET_WRITE_DIR
    IN R16, DDRB 
    OR R16, BMASK 
    IN R17, DDRD 
    OR R17, DMASK
    OUT DDRB, R16 
    OUT DDRD, R17
.endm

误用

or
- 应该使用
ori
。初学者的错误!


0
投票

自从您发布问题近两年后,它的价值是多少。万一其他人遇到这个问题(就像我一样),这就是对我有用的语法

MacOS, Arduino IDE 2.3.2
:

#define CS_PORT PORTA
#define CS_PIN  0B11

.macro PIN_HIGH port, pin // (port, pin)
    SBI &port, &pin
.endm

.macro CS_IDLE         
    PIN_HIGH CS_PORT, CS_PIN 
.endm

这是生成的汇编代码的片段:

  CS_IDLE
 180:   13 9a           sbi     0x02, 3 ; 2
© www.soinside.com 2019 - 2024. All rights reserved.