So I found this code on the wiki and it seems to work:
but two's complement is normally inverting all the bits and then adding 1, so that e.g. $00 = $FF + $01 = $00 (where the addition, in this case, results in the carry flag being set).
However
does not seem to yield a = 0.
What am I missing about the carry flag and why would it make a difference whether it's set before the adc instruction in the first code example? And why add with 0 instead of with 1?
Code:
; A = -A
eor #$FF
sec
adc #0
eor #$FF
sec
adc #0
but two's complement is normally inverting all the bits and then adding 1, so that e.g. $00 = $FF + $01 = $00 (where the addition, in this case, results in the carry flag being set).
However
Code:
lda #$00
eor #$FF
adc #$01
eor #$FF
adc #$01
does not seem to yield a = 0.
What am I missing about the carry flag and why would it make a difference whether it's set before the adc instruction in the first code example? And why add with 0 instead of with 1?