[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] How to do multi-line assembler macros?
From: |
Brian Dean |
Subject: |
[avr-gcc-list] How to do multi-line assembler macros? |
Date: |
Tue, 9 Sep 2003 11:43:30 -0400 |
User-agent: |
Mutt/1.4.1i |
Hi,
I'm writing some assembler routines where the use of C #define macros
would make my life a lot easier. I need to write a macro of the form:
lds r0, servo_0
tst r0
brne servos_reset_0_over_1
cbi SERVO_0_PORT, SERVO_0_BIT
rjmp servos_reset_0_over
servos_reset_0_over_1:
sbi SERVO_0_PORT, SERVO_0_BIT
There are lots of servos, so I'd like to write a macro like this:
#define RESET_SERVO(servo) \
lds r##servo, servo_##servo ;\
tst r##servo ;\
brne servos_reset_##servo##_over_1 ;\
cbi SERVO_##servo##_PORT, SERVO_##servo##_BIT; \
rjmp servos_reset_##servo##_over; \
servos_reset_##servo##_over_1: \
sbi SERVO_##servo##_PORT, SERVO_##servo##_BIT; \
servos_reset_##servo##_over:
To be used like so:
RESET_SERVO(0)
RESET_SERVO(1)
...
However, the macro expands as follows:
lds r0, servo_0 ; tst r0 ; brne servos_reset_0_over_1 ; cbi ((0x1B) +
0), 0; rjmp servos_reset_0_over; servos_reset_0_over_1: sbi ((0x1B) + 0), 0;
servos_reset_0_over:
Thus, due to the ';' character identifying the beginning of a comment,
only the first 'lds r0, servo_0' instruction is actually assembled.
I've tried preceding the continuation character '\' with '\n' thinking
maybe that would direct the preprocessor to generate linefeeds, but it
didn't. Also, if I remove the ';', I get the assembler error: "Error:
garbage at end of line".
Is there a way to make this work using #define macros?
BTW, this construct works just fine using the native i386 gas
assembler. Maybe it treats ';' as "end of instruction" instead of
"beginning of comment". Could the assembler syntax be that different
to treat the meaning of ';' different between the two targets (AVR vs
i386)?
Does anyone know how to do this and make it work?
Any help is appreciated.
Thanks,
-Brian
--
Brian Dean, address@hidden
BDMICRO - Maker of the MAVRIC ATmega128 Dev Board
http://www.bdmicro.com/
- [avr-gcc-list] How to do multi-line assembler macros?,
Brian Dean <=
Re: [avr-gcc-list] How to do multi-line assembler macros?, Brian Dean, 2003/09/09