Skip to content

Fix high-byte subtraction  #3

@taeber

Description

@taeber
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)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions