6502js
6502js copied to clipboard
No error for undefined labels
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. :-/
Confirmed. Not sure what to do about it!
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.