3 ms·
ADC = A + V + C 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 b
by mkagenius 7y ago
ADC = A + V + C
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?
- ltriant 7y agoWow, yeah, that's a bit off. And incorrect. It should end up being equivalent to: SBC = A - V - 1 + C Thanks. I'll fix this up :)
- mkagenius 7y ago> but the - 1 is taken care of because of the fact that ADC and SBC do the opposite thing with the carry flag. 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
- ltriant 7y agoAh yeah you’re right. I had a brain fart and got my -V and !V confused. At the time of writing I was sure I had it right too! I’ll fix that up. Thanks :)
- carlmr 7y agoI think it looks odd, too. If you go with this: 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 SBC instruction subtracts a value from the accumulator register, with an extra 1 subtracted from the result if the carry flag is NOT set." 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.