alberthdev / spasm-ng

SPASM-ng is a z80 assembler with extra features to support development for TI calculators.
GNU General Public License v2.0
97 stars 23 forks source link

`#define` order difficulties #48

Open AndrewMHenry opened 7 years ago

AndrewMHenry commented 7 years ago

Hi there!

While assembling a TI-83 Plus series application with spasm-ng, I discovered that one of my macros (defined in terms of other macros using #define) was taking on different values when used in different places. After some digging, it seems that the values differed depending on whether or not one of the macros used in the definition was evaluated before substitution. To illustrate the problem, I've attached a small example that exhibits the same behavior, along with a listing file that shows the discrepancy. (The listing file was generated by SPASM-ng v0.5-beta.3 - Beta Release, the most recent release at the time of this writing.)

Assuming that evaluation before substitution is the desired behavior, this is easy enough to work around by simply putting otherwise ambiguous macro references in parentheses. For example, replacing product with (product) in the definition of result on line 13 of the example produces the desired result. However, I think it might save development time to have macros always evaluate to the same value. Any ideas or feedback would be appreciated.

Thanks, Andrew Henry

Attachments: listing.txt source.txt

P.S.: Sorry for closing and re-opening this issue; I accidentally hit Ctrl+Enter before I finished writing it.