1
\$\begingroup\$

I have attempted to make an 4 bit Adder and Subtractor circuit on Logisim, but i've came across a problem. So the Adder works but the subtractor doesn't. When i do subtraction the 1 thats carried in is carried throughout the circuit. When i do 1000 - 1000 it gives me 10000.

How do i solve this?

\$\endgroup\$
3
  • 3
    \$\begingroup\$ I believe you can use a hierarchical design in Logisim. This way you can build a basic block (one-bit adder) and reuse it. It will simplify things for everyone. \$\endgroup\$
    – Eugene Sh.
    Commented Jul 3, 2019 at 16:16
  • \$\begingroup\$ Thank you for helping!, I should have mentioned this but unfortunately our assignment requires us to have 4 bit adder within the one diagram. He wants us to use logic gates etc to build this. \$\endgroup\$
    – Amy.C
    Commented Jul 3, 2019 at 16:29
  • \$\begingroup\$ @A.C that's fine, but I'd recommend going Eugene's route for the design; first built it using hierarchical things (they are still made of logic gates! You just can't see them!), and if your assignment requires it, replace each instance of the hierarchical design with its "contents". \$\endgroup\$ Commented Jul 3, 2019 at 18:18

3 Answers 3

0
\$\begingroup\$

The circuit works fine. Your output is actually 5 bits. So

\$1000_2 - 1000_2 = 1000_2 + (-1000_2) = 1000_2 + 1000_2 = 10000_2\$

Note that the most-negative-number in any 2's-complement representation can not be negated to give a valid positive value. For 4 digits, the most-negative-number is \$1000_2 = -8_{10}\$ and you can't represent +8 in a 4-bit 2's-complement value.

\$\endgroup\$
3
  • \$\begingroup\$ I agree that the circuit worked as expected. What does the answer 10000 mean? \$\endgroup\$
    – devnull
    Commented Jul 3, 2019 at 17:54
  • 1
    \$\begingroup\$ It depends on how you interpret it. The correct way to interpret it would be that a 4-bit operation produced a result of 0000 with a carry out. Your point, I think, is well taken that if we interpret this as a 5-bit integer the value is still invalid. My point of view was that as a 4-bit subtractor with a 4-bit result, the result was correct. \$\endgroup\$ Commented Jul 3, 2019 at 18:09
  • \$\begingroup\$ One could extend the 2s complement to 5 bits so subtracting will get the correct result. The circuit above just complements 4 bits and adds a carry in. Fix is: 1000 - 1000 = 1000 + 10111 + 1 = 00000 \$\endgroup\$
    – stark
    Commented Jul 3, 2019 at 19:23
0
\$\begingroup\$

When you calculate the two's complement of 1000 you get 1000. The range of possible signed integers with 4 bits is: -8 to 7.

When selecting the subtract option, the largest positive number in the input which will have its value negated is 7 (0111).

Your circuit is giving the expected (invalid) result since the second input number is not in the acceptable range for the subtraction operation.

\$\endgroup\$
3
  • \$\begingroup\$ No, a 4-bit output of 1000-1000 should be 0000. The output is actually correct. \$\endgroup\$ Commented Jul 3, 2019 at 17:19
  • \$\begingroup\$ The question said the answer is 1000 not 10000. Should we edit it to fix this? \$\endgroup\$
    – devnull
    Commented Jul 3, 2019 at 17:49
  • \$\begingroup\$ Thanks guys for helping me! @vangelo I've just edited my question. \$\endgroup\$
    – Amy.C
    Commented Jul 3, 2019 at 18:55
0
\$\begingroup\$

For generating carry you can use simpler logic of cascading half adders. So basically you create a simple circuit of full adder and save it and then reuse it in a new file multiple times. It will make your circuit cleaner

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.