Jump to content
IGNORED

DASM macro parameter problem


Recommended Posts

Any idea how to pass variables instead of constant numbers to a macro?

 

E.g. instead of "MACRO 1" I would like to do "MACRO variable". But when I do this outside an expression, inside the macro {1} is converted into the string "variable" and not the content of the variable.

 MAC TEST
Label{1}
   .byte {1}
 ENDM  

variable SET 10
 TEST variable

This works for the .byte instruction, but not for the label. I get "Labelvariable" instead of "Label10". :(

 

Any ideas?

Link to comment
Share on other sites

Any idea how to pass variables instead of constant numbers to a macro?

 

E.g. instead of "MACRO 1" I would like to do "MACRO variable". But when I do this outside an expression, inside the macro {1} is converted into the string "variable" and not the content of the variable.

 MAC TEST
Label{1}
   .byte {1}
 ENDM  

variable SET 10
 TEST variable

This works for the .byte instruction, but not for the label. I get "Labelvariable" instead of "Label10". icon_sad.gif

 

Any ideas?

I have an idea, but you might not like it-- although it's the only thing I could get to work.

 

Define a macro called LABEL, as follows:

 

  MAC LABEL
  if <{1} == 0
Label0
  endif
  if <{1} == 1
Label1
  endif
  if <{1} == 2
Label2
  endif
; etc.
  if <{1} == 10
Label10
  endif
; etc., up to
  if <{1} == 255
Label255
  endif
  ENDM

This assumes that the variable you're going to pass to your macro will be set to a value between 0 and 255.

 

Then you can call the LABEL macro from inside your other macro, as follows:

 

  MAC TEST
  LABEL {1}
  BYTE {1}
  ENDM

Then this works:

 

variable SET 10
  TEST variable

The output is as follows:

 

Label10
  BYTE variable ; which gives you a byte of $0A

The only reason I suggest defining a macro called LABEL is in case you want to call it from inside multiple macros.

Michael

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...