Possible Error With Unary '-' Operator in ASM6

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
beneficii
Posts: 127
Joined: Tue Jul 12, 2005 4:37 pm

Possible Error With Unary '-' Operator in ASM6

Post by beneficii »

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?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

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: Select all

  lda #>(table + 8)
  sta 1
  lda #<(table + 8)
  sta 0
User avatar
loopy
Posts: 403
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Post by loopy »

Thanks for catching that. I fixed it.
User avatar
beneficii
Posts: 127
Joined: Tue Jul 12, 2005 4:37 pm

Post by beneficii »

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.
User avatar
loopy
Posts: 403
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Post by loopy »

Ahem... that would be an error in the readme. Fixed it. :oops:
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

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 :)
Post Reply