AVRASM2: problem using #define, .def/.undef, and macros

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has anybody run into problems using the preprocessor with macros?

I'm trying to find a way to keep track of my registers with AVRASM2 using #defines and macros with .def'd registers. This works well.. until I try to use it in my code. The macros are in one file, with the code and #defines in a few .asm files. I don't know if that has anything to do with it or not.

A simple example such as this works fine, but now it says "Operand 1: Invalid register." Operand 1 beng something I #defined ('bits' or 'avail' in my example listing) after calling my def_GetBits macro.

When I try to use #defines I also see the assembler complaining about a "macro body spanning an EOF" as if I missed an .endm directive, or "unexpected , (comma)" as if the #defined symbol equates to nothing.

Anyhow.. this works, but I'm trying to find a simple example that doesnt work.

/* GetBits */
.macro def_GetBits
    .def GB_bits    = r24
    .def GB_avail   = r22
    .def GB_buffer  = r25
    .def GB_dest    = r23
.endm
.macro undef_GetBits
    .undef GB_bits
    .undef GB_avail
    .undef GB_buffer
    .undef GB_dest
.endm

; GetBits - do something
def_GetBits
#define bits  GB_bits
#define avail GB_avail

GetBits:
    ldi avail, 0xAA
    ldi bits, 0xBB
	sub bits, avail
	; do something
	ret

#undef bits
#undef avail
undef_GetBits

/* John Butera */

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found the problem in my code. One of my lines was...

#define dest

with a newline before saying what dest should be. This set off many more errors.

My code assembles now without error, but I don't believe that this was the only problem I've had. I'm sure I'll come across whatever else it was that I thought was causing problems.

/* John Butera */

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pepsi wrote:
I found the problem in my code. One of my lines was...

#define dest

with a newline before saying what dest should be. This set off many more errors.

My code assembles now without error, but I don't believe that this was the only problem I've had. I'm sure I'll come across whatever else it was that I thought was causing problems.

The AVRASM2 preprocessor works mostly like the C preprocessor (see the Studio help for exceptions). Accordingly, if you don't provide a value with a #define statement, the value will be set to 1.

You can split a #define statement using line continuation, i..e., a backslash as the last character of a line causes the next line to be appended to it (this works for all source lines).

Example:

#define FOO \
        2 * (3 \
        + 2)

is the same as:

#define FOO   2 * (3 + 2)

If you are experiencing problems with the preprocessor, I recommend upgrading to Studio 4.10, it comes with AVRASM2 Beta5, where a lot of preprocessor-related bugs are fixed.

Roland Kruse
Atmel AVR Tools

Please don't report bugs in private forum messages.
--
Roland Kruse
Atmel AVR Tools