Arakula / A09

A09 6800/6801/6809/6309/68HC11 Assembler
GNU General Public License v2.0
40 stars 8 forks source link

Label on the same line as a macro is not defined #1

Closed gordonjcp closed 8 years ago

gordonjcp commented 8 years ago

I'm not sure if I'm just not understanding some subtlety of macros or if this is actually a bug. I've compiled A09 on Linux and it works. If I define a macro which in this case inserts a string with a trailing NUL then when I put it on the same line as a label, on pass 2 I get "Error 3: undefined label".

If I put a newline after my label "blip" then it works as expected.

fccz  macro
      fcc &1
      fcb 0
      endm

begin ldd #blip
      bra begin

blip  fccz 'string'
Arakula commented 8 years ago

To be honest, after some investigation, I am still unsure whether this is an error in A09 or not, but I lean very slightly towards "it's correct". The Flex ASMB documentation mentions a way to achieve what you want:

There is actually a tenth parameter which may be passed into a macro represented by the dummy parameter "&0". It is presented on the calling line as so: <prm.0> MACNAM <prm.l>,<prm.2>,<prm.3>,...,<prm.9>

This parameter is somewhat different from the others in that it must be a string of characters that conform to the rules for any other assembly language label since it is found in the label field. It is in fact a standard label which goes into the symbol table and can be used in other statement’s operands like any other label.

In your context, that means: if you rewrite your macro a little bit so that it looks like:

fccz macro
&0 fcc &1
   fcb 0 endm

, the invocation

blip fccz 'string'

has the desired effect to generate

+0005 737472696E67 BLIP fcc 'string'
+000B 00 fcb 0

(you can examine the macro expansion by putting an OPT EXP line at the start of your assembler source).

Arakula commented 8 years ago

Still not sure, but the documentation might also be interpreted as "set the label and pass it to the macro as &0. Hmmm... tricky, this one.

A09's current approach is more flexible IMO (you can put the label anywhere you want in the macro expansion), but might conflict with existing macro libraries, if they assume that the label is both set and passed as &0. Unfortunately, I don't have any reference library at hand, so I can't tell.

I'll add an option for that, since I can't really determine which way is better.

In any case, as soon as my time permits, I'll fire up a FLEX09 emulator and look what the original ASMB and RELASMB programs do in this case.

Arakula commented 8 years ago

OK; I uploaded a new version, which has the DLM | NDL* options added.

OPT DLM can be used to force A09 to define the label on a macro call line. Using OPT DLM, your original macro example

fccz  macro
      fcc &1
      fcb 0
      endm

begin ldd #blip
      bra begin

blip  fccz 'string'

works. Attention: in this mode, &0 may only be used as a label name up to and including the first code-emitting line in the macro. On any line after that. A09 will complain about multiple definitions.

OPT NDL (default, and standard behavior in previous versions) doesn't implicitly define the label; in this case, the label name is simply passed into the label expansion as &0, but the macro has to contain an appropriate &0, so your macro has to be written as

fccz  macro
&0    fcc &1
      fcb 0
      endm

to work.

gordonjcp commented 8 years ago

Wow, I hadn't even had a chance to test the workaround :-) I suspected that it would be something like that. Thanks !