spasm-ng icon indicating copy to clipboard operation
spasm-ng copied to clipboard

equ directive should support operator precedence in its arithmetic expressions

Open bxparks opened this issue 1 year ago • 3 comments

Problem

The equ directive can contain arithmetic expressions. But apparently, there is no support for operator precedence. So the following equ statement:

helloRowCol equ helloRow + $100*helloCol

is currently interpreted as (helloRow+$100) * helloCol.

The correct expression has to be written as:

helloRowCol equ helloRow + ($100*helloCol)

as done in #82, but this is very easy to forget.

Expectation

  • The equ directive should support basic operator precedence, so that multiplication * and division / has a higher precedence than addition + and subtraction -`.
  • If there are other operators supported by the equ, a reasonable order of precedence would be to follow the same rules as the C language.

bxparks avatar Jun 22 '24 16:06 bxparks

As far as I'm aware, this is intentional design for compatibility with TASM.

calc84maniac avatar Jun 22 '24 16:06 calc84maniac

Interesting. In that case, this is a place where a non-fatal warning message would be useful. In other words, if the current left-to-right operator precedence rule would produce a different result than the MDAS rule that many people would expect.

bxparks avatar Jun 22 '24 16:06 bxparks

It would be nice to have a flag to use proper precedence.

Eeems avatar Jun 22 '24 16:06 Eeems