flamewing / asl-releases

Improved/bugfixed version of Alfred Arnold's The Macro Assembler AS
http://john.ccac.rwth-aachen.de:8000/as/
GNU General Public License v2.0
20 stars 2 forks source link

A stable way to make "array" variables #4

Closed Awuwunya closed 3 years ago

Awuwunya commented 3 years ago

I remember this back from the day of working on AMPS. I used to not have an external tool to deal with music or SFX, I actually sort of hackily constructured arrays. Like for example, variable0, variable1, variable2, etc...

I tried to make this happen in AS, but despite my best efforts, it would never work out like I expected at all. I'm not even aware if this is possible in the first place, but making it possible would allow for some... "unconventional" programming features to exist. Specifically, my problem was that I could not figure out how to fetch values, so it was difficult to tell if I was even storing values correctly in the first place. I would never get out anything that made sense.

ASM68K, oddly enough, allows this to work despite it probably not being intentional:

; store:
ix = 0
variable\$ix    = 1234

; load to variable
ix = 0
temp    equs variable\$ix
data =  \temp

Since assemblers don't really support arrays, you can't do some things so easily, and this is one way to work around it, but I was never able to figure out how to make AS do the equivalent, sadly.

flamewing commented 3 years ago

It can be done in the following way:

; store:
ix := "0"
variable{ix} := 1234

; load to variable
ix := "0"
temp := variable{ix}
    message "variable\{ix} is \{temp}"

If you try with integer ix, it will fail; I guess I should make AS just stringify the integer in this case, as it is an arbitrary error.