Jump to content



1

DASM macro parameter problem


1 reply to this topic

#1 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Mon Mar 7, 2011 6:13 AM

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?

#2 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,545 posts
  • Location:Georgia, USA

Posted Mon Mar 7, 2011 11:45 PM

View PostThomas Jentzsch, on Mon Mar 7, 2011 6:13 AM, said:

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". Posted Image

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







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users