Open dwsJason opened 5 years ago
I'm not familiar with variable number of arguments macros, I need to read up on it, is there another assembler that handles it? I'm only familiar with IBM's IDR directive. the macro arguments are always expanded as strings and the macro is then assembled as if it was a scope, it doesn't analyze the argument types but that means that the arguments can be another macro, or you can supply the address mode with the argument itself. I have created macros that append lines to a string, then assembles the resulting string to build more complicated conditional macros. maybe there is something that can be done by identifying a prefix, like a switch/case statement in C.
In SNASM assembler, I believe there are 2 auto generated variables. numargs, and arg0, then a special command inside the macro that called shiftargs, which will shift the next argument into arg0.
With Merlin you do not have to name the input arguments, you just access them with ]1, ]2, ]3, etc ... so I think there’s a couple different ways.
I’d love to see an example of how you would implement the Push32. Where if an address is passed in it would load / Pham the values from memory, or if a constant is passes in it would use PEA instructions.
Thank you in advance, Jason
On Sep 30, 2019, at 01:56, Carl-Henrik Skårstedt notifications@github.com wrote:
I'm not familiar with variable number of arguments macros, I need to read up on it, is there another assembler that handles it? I'm only familiar with IBM's IDR directive. the macro arguments are always expanded as strings and the macro is then assembled as if it was a scope, it doesn't analyze the argument types but that means that the arguments can be another macro, or you can supply the address mode with the argument itself. I have created macros that append lines to a string, then assembles the resulting string to build more complicated conditional macros. maybe there is something that can be done by identifying a prefix, like a switch/case statement in C.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
For example, if I use the built in dc.w, I can put a variable number of inputs
dc.w funthing, funthing2, funthing3
If I want to alias da, to dc.w, it's unclear to me how I make that happen, since the macro will have to have a fixed number of arguments.
da funthing1, funthing2, otherthings, andmorethings
Does this make more sense?
It would be so great to be able to do something like this: macro da { repeat _numArgs { dc.w _args[_reptIndex] } }
or if easier macro da { repeat _numArgs { dc.w _arg shiftargs ; basically arg0 becomes arg1, arg1 becomes arg2 .... etc } }
I'm having a difficult time trying to figure out how to do a few different things with the macros. Is there a mechanism to do a variable number of arguments to a macro? Is there a mechanism that will me see what type of argument is supplied (constant #), vs address.
For example if you wanted to make a macro, like Push32, I would want it take either #immediate value, or an $address, for address we want to generate code that does, lda addr, pha, lda addr+2, pha... but if it was immediate. pea #addr, and pea #^addr. It would be great to be able to use the same macro, to achieve both.