Hi, I've been successful in understanding chapter 2 up until now - however, my problem lies in the ALU's table of functions on page 37... particularly with the subtractions. Previously it said that subtraction is performed like so:
x - y = x + (-y)
where -y = two's complement of y; involving inverting its bits and adding 1. But the ALU seems to use a completely different method - invert x's bits, add them to y, and invert the result...? Apologies if I'm missing something, but it doesn't appear to describe this anywhere else, leaving me wondering how they actually came up with this method and why it's used instead... help please? :P
That you can get x-y using the adder (without a Carry-In) and bitwise inversions is not intuitively obvious, but you CAN get there from the goal and what capabilities you have.
If we have proven that, in two's complement, the relationship between the additive inverse of n and the bitwise inverse is
-n = ~n + 1
then we can solve for ~n to get
~n = -(n+1)
With this relation, we can proceed as follows:
Z = x - y
Z = x - y + 1 - 1 // We know we need some +1 in there to use our relation
Z = -(y - x - 1 + 1) // We know we need a minus out front to use our relation
Z = -((y - x - 1) + 1) // This is the form of our relation with n = (y-x-1)
Z = ~(y - x - 1) // Applying our relation
Z = ~(-(x + 1) + y) // Getting part of the interior into the form of our relation
Z = ~(~x + y) // Applying our relation
In the interests of full disclosure, I didn't come up with that derivation the way I would love to be able to claim. I basically walked the proof that the logic circuit performs the subtraction backwards and then figured out a plausible motivation for making each forward step.
I seriously doubt I would have every come up with that design on my own, though I would not be surprised to discover that it's been around for decades.
It's extremely clever and I like elegance of it, but I imagine using the carry-in is the better way to go in a real design.
But understanding how the forward design could have been arrived at does tend to flesh out the set of thinking tools in your kit, and that's seldom a wasted of effort.