0

I have a macro which creates labels, but I only want to create those labels if they aren't already defined. The problem is that the label is built using a macro argument, and the assembler doesn't like symbols generated using macro arguments. This is the code that doesn't work. It errors out on the ifndef. Is there any other way to write this?

.macro create_handler modifier
  .ifndef handler\modifier
    handler\modifier:
    some code
    some more code
  .endif
.endif

Error: junk at end of line, first unrecognized character is `\'

bja1288
  • 9
  • 1
  • 4

1 Answers1

1

I think there are two problems. One is that \modifier: looks for a macro argument named modifier:, with the colon. You need to use \modifier\(): instead. \() breaks up the string so the parser knows that you have just ended the name of the argument.

Second, the last .endif should be a .endm:

.macro create_handler modifier
  .ifndef handler\modifier
    handler\modifier\():
      .4byte 0
  .endif
.endm

create_handler foo
create_handler foo

This results in this listing (ignore the line numbers, I added this to one of my existing files):

  74 0010 00000000  create_handler foo
  75                create_handler foo
DEFINED SYMBOLS
  ../src/core_dict.S:74     .text:00000010 handlerfoo

As you can see, only one handlerfoo was created.

Robert B
  • 3,195
  • 2
  • 16
  • 13