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

Fix high-byte subtraction #3

Open
taeber opened this issue Jul 1, 2022 · 0 comments
Open

Fix high-byte subtraction #3

taeber opened this issue Jul 1, 2022 · 0 comments

Comments

@taeber
Copy link
Owner

taeber commented Jul 1, 2022

PRPLA EQU $FDE2
      LDX #>PRPLA-1

Should assemble to A2 FD, not A2 FE.

I think this is happening because num is unsigned, so -1 becomes 0xFFFF (then saved as 0xFF).

Adding 0xFF to 0xFDE2 results in 0xFEE1 and the high-byte 0xFE is returned.

Repro

func TestHighByteSubtraction(t *testing.T) {
	out := bytes.NewBuffer(nil)
	prg := strings.NewReader(`
PRPLA	EQU $FDE2
	LDX #>PRPLA-1
	`)

	_, err := Assemble(out, prg, true)
	if err != nil {
		t.Error(err)
		return
	}

	// 0000-	A2 FD   	LDX #>PRPLA-1
	expected := []byte("\xA2\xFD")

	actual := out.Bytes()
	if !bytes.Equal(expected, actual) {
		t.Errorf("Expected %v; got %v", expected, actual)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant