SBC = A - V - (1 - C)
SBC = A + (-1 * (V - (1 - C)))
SBC = A + (-V + (1 - C))
SBC = A + -V + 1 + C
I am not able to follow the mathemagic behind the third line. Is it normal algebra or its in 1's complement?
ADC = A + V + C SBC = A - V - (1 - C) SBC = A + (-1 * (V - (C - 1))) SBC = A + (-V + (C - 1)) SBC = A + -(V + 1) + C
The explanation fits though. If the carry flag is not set (C == 0) then you subtract an extra 1. If C == 1 then it's A-V.
SBC = A - V - 1 + C
Thanks. I'll fix this up :)
Also, this line is bothersome, they do opposite things but that's why you have already done (1 - C).
Maybe the fact that -V is actually (!V + 1) (in 2's complement) that eats up the extra -1 is the correct explanation?
So,
SBC = A - V - 1 + C SBC = A + !V + 1 - 1 + C SBC = A + !V + C
At the time of writing I was sure I had it right too!
I’ll fix that up. Thanks :)
SBC = A - V - (1 - C)
SBC = A + (-1 * (V - (1 - C)))
SBC = A + (-V + (1 - C))
SBC = A + -V + 1 + C
I am not able to follow the mathemagic behind the third line. Is it normal algebra or its in 1's complement?