I've been writing a NES emulator, and am a bit confused about treating 8-bit values as signed or unsigned. I think I mostly understand that it doesn't matter except with what you do with the flags afterwards, but what about comparing operations?
According to http://www.obelisk.demon.co.uk/6502/reference.html#CMP the carry flag is set if A is >= to M (or X, Y for CPX, CPY respectively). So it seems that whether the values are signed or unsigned really does matter within the instruction itself, not just how you treat the results.
For example
So does BCS branch? The 2nd line will cause the carry flag to be set if we're dealing with unsigned values (255 > 5), and not if we're dealing with signed values (-1 < 5).
Another confusing thing is whether SBC/ADC set the overflow if the result exceeds the possible values for a signed value, or an unsigned value. So:
Does this set the overflow flag? It seems like it would if we're dealing with signed values, and not if we're dealing with unsigned values.
Anyway, any help would be greatly appreciated!
According to http://www.obelisk.demon.co.uk/6502/reference.html#CMP the carry flag is set if A is >= to M (or X, Y for CPX, CPY respectively). So it seems that whether the values are signed or unsigned really does matter within the instruction itself, not just how you treat the results.
For example
Code:
LDA $#FF
CMP $#05 ; Compare A (0xFF) with 0x05
BCS someoffset
CMP $#05 ; Compare A (0xFF) with 0x05
BCS someoffset
So does BCS branch? The 2nd line will cause the carry flag to be set if we're dealing with unsigned values (255 > 5), and not if we're dealing with signed values (-1 < 5).
Another confusing thing is whether SBC/ADC set the overflow if the result exceeds the possible values for a signed value, or an unsigned value. So:
Code:
CLC
LDA $#7F ; A = 127
ADC $#01 ; 127 + 1 = 127
LDA $#7F ; A = 127
ADC $#01 ; 127 + 1 = 127
Does this set the overflow flag? It seems like it would if we're dealing with signed values, and not if we're dealing with unsigned values.
Anyway, any help would be greatly appreciated!