John,
I'll do my best to explain it as I understand it. My examples will use a 4 bit number for simplicity.
In order to do a subtraction in hardware, its usually easier to take the two's compliment of the second number and then add the two numbers together. In that way, you only need a hardware adder to do both addition and subtraction.
Now, to take the two's compliment of a number, you invert the bits and then add 1.
Example:
0101 = 5
1010 = -6 (invert the bits, or one's compliment, or EOR $FF)
1011 = -5 (add 1)
Now, instead of adding the 1 seperately, why not just set the Carry and do an ADC command, saving an extra cycle!
Here are two examples:
Code:
Example 1:
1101 : 13
- 0110 : 6
---------------
1 : Carry Set
1101 : 13
1001 : -7 (one's comp)
-----------
10111 : 7 with the carry bit set (no borrow)
Example 2:
1101 : 13
- 1110 : 14
---------------
1 : Carry Set
1101 : 13
0001 : -15 (one's comp)
-----------
01111 : -1 with Carry Clear (borrow)
That how I understand it. I hope its clear to you.
Daryl
http://65c02.tripod.com/