Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gordonjcp opened this issue Jun 15, 2016 · 4 comments
Closed

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

gordonjcp opened this issue Jun 15, 2016 · 4 comments
Assignees

Comments

@gordonjcp
Copy link

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
Copy link
Owner

Arakula commented Jun 16, 2016

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 Arakula self-assigned this Jun 16, 2016
@Arakula
Copy link
Owner

Arakula commented Jun 16, 2016

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 added a commit that referenced this issue Jun 16, 2016
See #1 for details
@Arakula
Copy link
Owner

Arakula commented Jun 16, 2016

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.

@Arakula Arakula closed this as completed Jun 16, 2016
@gordonjcp
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants