6502js icon indicating copy to clipboard operation
6502js copied to clipboard

No error for undefined labels

Open phf opened this issue 10 years ago • 2 comments

In certain cases undefined labels don't lead to errors. Here's an example:

lda notfound,y lda found,y sta $0 brk

found: brk brk

Assemble this and you won't get an error message for "notfound" instead the assembler will silently insert $1234 as the address. Something is obviously wrong when you resolve labels, however I don't have enough JavaScript fu to fix this myself right now. :-/

phf avatar Oct 03 '13 22:10 phf

Confirmed. Not sure what to do about it!

BigEd avatar Oct 11 '13 09:10 BigEd

I believe TC01/6502js@6b87a152ff28013783f26aaa2319ead8271c12a3 fixes this issue.

The change I made was pretty simple. checkAbsolute, checkAbsoluteX, and checkAbsoluteY all have logic for detecting undeclared labels (that's where 0x1234 is inserted), but they return true, as if no error was encountered. All that was required to make the assembler detect this as an error was to change the "true" to "false" in the code block below (as you can see from the commit).

    } else {
        pushWord(0x1234);
        return true;
    }

I'm assuming there was a reason for inserting 0x1234 and returning success instead of just returning failure, though. That makes me a little skeptical that I may have accidentally broken a corner case here- but I can confirm it fixes the bug. And everything else at least appears to work.

TC01 avatar Jan 30 '14 03:01 TC01