10-31-2015, 09:16 PM
There's a warp: /warp hexcca
So, I finished my hex adder earlier this week. It is actually based on a subtraction algorithm I made up, to skip over the double inversion malarkey of your conventional hex adders. I just wired the inputs to default to 2's complement inversion on the B (-) input and inverted the Cin and Cout to make it an adder.
More photos:
I tried to draw out the algorithm here:
Explanation of the subtraction algorithm:
I hope that makes sense?
So, I finished my hex adder earlier this week. It is actually based on a subtraction algorithm I made up, to skip over the double inversion malarkey of your conventional hex adders. I just wired the inputs to default to 2's complement inversion on the B (-) input and inverted the Cin and Cout to make it an adder.
More photos:
I tried to draw out the algorithm here:
Explanation of the subtraction algorithm:
The first thing I did was do A-B and B-A. If B was greater than A, then that means the B-A part is on. I need to do some extra processing in that case, as it is a negative result.
Otherwise, I pass the result (the A-B output) to the end of the adder.
Oh, also since only one of those two outputs can be on at a time, I can OR those together later no bother, so keep that in mind.
Processing the case of B-A > 0
Now, let's deal with what happens when we find out we need to borrow.
So for a borrow, I take that B-A output and do 0x10 - (B-A). This is done by subtracting 1 from the B-A signal, and then inverting it like this:
Now, you might notice that the output of this inverter thing is still going to be F on 0 signal, the same as if there was a 1. This is bad, as there will be an F outputting when we don't want anything at all. (when B-A is 0, we want to be using the A-B output instead!)
The next thing to do is put a check for 0 on the B-A output. When the output is 0, we will disable that specially inverted output. After this, you're done processing the B-A output
Interfacing with a CCA carry tower:
From the B-A output, you will be generating a 'borrow' signal if it is on. Just pretend you're generating a carry and you'll be ok
that borrow signal goes into the generate input of a CCA carry tower. There is a trick here that I do which saves a tick, but it isn't necessary so I'll leave It out for simplicity's sake.
From the A-B output, you will be getting a 'borrow cancel' signal. Plug this in to the carry cancel input of the CCA carry tower.
Final steps and a special case
OK, that's about a half of the logic taken care of! Now to deal with the final subtraction and a special case.
So, now I have two outputs (A-B and the processed B-A) and a borrow output from the CCA carry tower. All I have to do now is to recombine the signals!
My two main outputs can be ORed together no problem, only one can be on at a time.
Next, I take the borrow signal, and if it is True I subtract 1 from the output. Obviously I do nothing if it is False.
Now there is a final special case, which is when A - B is 0. This is the subtraction equivalent of a propogate signal. It actually works fine on the existing hardware up until the point where a borrow is required. If you can do basic hex arithmetic you'll realise that 10 - 01 = F, but I can't do 10 - 1 with a comparator!
What I can do though is take my borrow signal and see if it is True while the other two inputs are 0. If these conditions are met, I can just override the output with full signal strength, which is F!
With that taken care of, the whole subtractor is done. (well, 1 layer. It stacks up to 8 layers)
phew
Otherwise, I pass the result (the A-B output) to the end of the adder.
Oh, also since only one of those two outputs can be on at a time, I can OR those together later no bother, so keep that in mind.
Processing the case of B-A > 0
Now, let's deal with what happens when we find out we need to borrow.
So for a borrow, I take that B-A output and do 0x10 - (B-A). This is done by subtracting 1 from the B-A signal, and then inverting it like this:
Now, you might notice that the output of this inverter thing is still going to be F on 0 signal, the same as if there was a 1. This is bad, as there will be an F outputting when we don't want anything at all. (when B-A is 0, we want to be using the A-B output instead!)
The next thing to do is put a check for 0 on the B-A output. When the output is 0, we will disable that specially inverted output. After this, you're done processing the B-A output
Interfacing with a CCA carry tower:
From the B-A output, you will be generating a 'borrow' signal if it is on. Just pretend you're generating a carry and you'll be ok
that borrow signal goes into the generate input of a CCA carry tower. There is a trick here that I do which saves a tick, but it isn't necessary so I'll leave It out for simplicity's sake.
From the A-B output, you will be getting a 'borrow cancel' signal. Plug this in to the carry cancel input of the CCA carry tower.
Final steps and a special case
OK, that's about a half of the logic taken care of! Now to deal with the final subtraction and a special case.
So, now I have two outputs (A-B and the processed B-A) and a borrow output from the CCA carry tower. All I have to do now is to recombine the signals!
My two main outputs can be ORed together no problem, only one can be on at a time.
Next, I take the borrow signal, and if it is True I subtract 1 from the output. Obviously I do nothing if it is False.
Now there is a final special case, which is when A - B is 0. This is the subtraction equivalent of a propogate signal. It actually works fine on the existing hardware up until the point where a borrow is required. If you can do basic hex arithmetic you'll realise that 10 - 01 = F, but I can't do 10 - 1 with a comparator!
What I can do though is take my borrow signal and see if it is True while the other two inputs are 0. If these conditions are met, I can just override the output with full signal strength, which is F!
With that taken care of, the whole subtractor is done. (well, 1 layer. It stacks up to 8 layers)
phew
I hope that makes sense?