Home › Practice › RTL Design › One circuit, two jobs
One circuit, two jobs
EasyRTLcombinationalarithmetic
A calculator chip has room for only one adder. You have to make that one adder able to subtract too.
Concept first. Subtracting b is the same as adding the opposite of b. In the previous problem you saw that the opposite of a two's-complement number is "flip every bit, then add one". So a - b can be computed with the same adder, if you can flip the bits of b only when subtracting, and sneak in one extra +1. Look for a gate that passes a bit through unchanged for one control value and inverts it for the other, and look for a free place in an adder where a +1 can go in.
What to build.
addsub4(a, b, sub): whensub = 0,y = a + b. Whensub = 1,y = a - b. Both are 4 bits and wrap.coutis the carry out of the adder inside your design.- No clock.
- Rule: do not use
+,-or comparisons. Build the adder from gates, as in the ripple adder problem.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.