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)
}
}
Should assemble to
A2 FD, notA2 FE.I think this is happening because
numis unsigned, so-1becomes0xFFFF(then saved as0xFF).Adding
0xFFto0xFDE2results in0xFEE1and the high-byte0xFEis returned.Repro