You will be creating an Adder/Subtractor, which can toggle between which of the two operations it is doing. Consider the fact that you have an existing component which can do 4-bit addition, and suppose that you want to be able to do A - B for some numbers A and B. Using what you’ve learned about Two’s Complement, you should know that A-B is the same as A + (-B).In Two’s complement, -B is the result of inverting B, and adding 1. In order to invert B, you can’t just use NOT gates, because you need to be able to turn on/off the inversion(since you want to use the same circuit for both addition and subtraction). In order to be able to toggle between inverting B(while subtracting) and using B as it is (while adding), you will need a component that works like the table below: INV A Q 0 0 0 0 1 1 1 0 1 1 1 0 When INV is 0, then Q just outputs whatever A is and when INV is 1, then Q outputs NOT A, which you should be able to see from the table. This table should be familiar to you as it exactly looks like the table for an XOR gate. As a result, if you pass in one of your inputs(B) as one of the inputs to an XOR gate, and use the other to control whether or not you are inverting, you can toggle whether you are adding or subtracting. In order to do the extra +1 for Two’s complement, you can just set Cin to 1. Otherwise, it should just be 0 by default, because you don’t want to carry anything into the adder when adding. Ultimately, your circuit should perform A + B when the SUB input is 0, and A + ~B + 1, with ~B being the inverse of B, and the +1 coming from Cin.
You will be creating an Adder/Subtractor, which can toggle between which of the two operations it is doing.
Consider the fact that you have an existing component which can do 4-bit addition, and suppose that you want to be able to do A - B for some numbers A and B. Using what you’ve learned about Two’s Complement, you should know that A-B is the same as A + (-B).In Two’s complement, -B is the result of inverting B, and adding 1. In order to invert B, you can’t just use NOT gates, because you need to be able to turn on/off the inversion(since you want to use the same circuit for both addition and subtraction). In order to be able to toggle between inverting B(while subtracting) and using B as it is (while adding), you will need a component that works like the table below:
INV |
A |
Q |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
When INV is 0, then Q just outputs whatever A is and when INV is 1, then Q outputs NOT A, which you should be able to see from the table. This table should be familiar to you as it exactly looks like the table for an XOR gate. As a result, if you pass in one of your inputs(B) as one of the inputs to an XOR gate, and use the other to control whether or not you are inverting, you can toggle whether you are adding or subtracting.
In order to do the extra +1 for Two’s complement, you can just set Cin to 1. Otherwise, it should just be 0 by default, because you don’t want to carry anything into the adder when adding. Ultimately, your circuit should perform A + B when the SUB input is 0, and A + ~B + 1, with ~B being the inverse of B, and the +1 coming from Cin.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images