This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Possible Error With Unary '-' Operator in ASM6

Possible Error With Unary '-' Operator in ASM6
by on (#43913)
The readme text for ASM6 says that the unary '-' operator has the second highest precedence (below only parantheses), but the program itself gives it the lowest precedence. When the unary '-' operator is processed, it is given a precedence of WHOLE_EXP, which is the lowest precedence in the program. Indeed, with tests, I have seen that a statement such as:

-5 + 3 * 9

is processed as though it were written:

-(5 + 3 * 9)

when, suggesting from the readme, it should be instead processed as though it were written:

(-5) + 3 * 9

Which yield two different results. It seems that every unary operator in ASM6 has this error. This would be easy to fix by adding a new precedence type higher than MULDIV, such as UNARY. Perhaps we can easily fix this?

by on (#43915)
C puts all its unary prefix operators in the same precedence, including ! and * and sizeof. So I guess it'd have precedent. But watch out: the < (extract bits 7-0) and > (extract bits 15-8) operators are also unary, and you'd need to parenthesize their arguments if they're calculated:
Code:
  lda #>(table + 8)
  sta 1
  lda #<(table + 8)
  sta 0

by on (#43916)
Thanks for catching that. I fixed it.

by on (#43938)
Not a problem. :)

One other smaller issue though is that the program and the readme have the '<' and '>' unary operators mixed up: the readme says '<' gives the upper byte and that '>' gives the lower byte, but in the program '<' gives the lower byte while '>' gives the upper byte.

by on (#43939)
Ahem... that would be an error in the readme. Fixed it. :oops:

by on (#44027)
hey thanks a lot for ASM6.. it's definitely the most straightforward NES assembler i've used

i might recommend including the NES101 tutorial in the ASM6 distribution file though :)