Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot 'lda' with the 'least significant' operator for certain negative numbers #5

Closed
svallee-dev opened this issue Jun 5, 2020 · 2 comments
Labels

Comments

@svallee-dev
Copy link

This is a very specific issue I have encountered when using this format:

lda #<NUM

Where NUM can be any number between 0 and 65535. With these positives numbers it works fine. It also seems to work fine with negative numbers... with the exception of numbers between -128 and -255 (inclusive).

For instance, these works:

lda #<-127
lda #<-256

But these doesn't:

lda #<-128
lda #<-200
lda #<-255

For any numbers between these two, assembly stops on this error:

Mode not supporter for "lda" in selected CPU.

@svallee-dev
Copy link
Author

svallee-dev commented Jun 5, 2020

Turns out there a few more issues with negative numbers (incl most significant byte not getting the $ff for negative numbers). So in case others have this issue and it doesn't get fixed in 6502.net, here is my work around, two functions that I'll now use instead of the < and > operators:

LEAST	.function val
			.if val < 0
				.return 255 & (256 - ((-val) % 256))
			.else
				.return <val
			.endif
		.endfunction
		
MOST	.function val
			.return val >> 8
		.endfunction

@informedcitizenry
Copy link
Owner

Thanks again for the feedback. A very subtle bug in how we're handling the LSB and MSBs, I should have a fix posted soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants