0
\$\begingroup\$

I want to implement unsigned subtraction using 2's complement. I arrived to this, where if I have 2 4-bit binary numbers A and B, I transform B to 2's complement (let us name it B' so we don't get confused) and then add A to B'and I get the result C. This was the easy part for me.

Then if the final carry out is "0" I should transform C to 2's complement and add a "-" sign, but if the carry out is "1" I just don't adjust anything. And this is where it got me. I don't know how to implement it and I should put a led in the final result to let know if the sign is "+/-".

I think I should put a 2-to-1 multiplexer where the select input will be the carry out of the circuit I posted.

And by the way, my implementation is correct, whenever I put random values and then calculate those by hand I get the same result.

Thank you in advance.
(The program I used is called "logicCircuit".

So this is what I got to.(After editing my post)

enter image description here

The circuit above is my main circuit.

enter image description here

enter image description here

These 2 pictures above are just zoomed in photos of the circuit

Now my question is, can I do something so I can get only one result. For example if the carry is "0" The multiplexer gives me the correct result, but in the same time I am getting a result in the upper part of my circuit which is the part that should give me a result whenever the carry is "1" and vice versa.

The gray bubble are leds so when the result is 1, the led lights up.

\$\endgroup\$
3
  • \$\begingroup\$ RE " if I have 2 4-bit binary numbers A and B, I transform B to 2's complement ", how many bits is the 2's complement result? If it's 4 bits, what do you do if B > 7? \$\endgroup\$ – The Photon May 2 '20 at 14:53
  • \$\begingroup\$ @ThePhoton the 2's complement result is also 4 bits. I don't want any of the inputs to be higher than 4-bits. \$\endgroup\$ – P_M May 2 '20 at 14:59
  • \$\begingroup\$ @PeterMurr Just in case you aren't thinking about it, make sure that if you complement an input, that you also either complement the carry-in or set it to 1 depending on the operation you desire. \$\endgroup\$ – jonk May 2 '20 at 19:02
1
\$\begingroup\$

I think I should put a 2-to-1 multiplexer where the select input will be the carry out of the circuit I posted.

Yes, that's all there is to it.

You have a multiplexer. One input to the multiplexer is the output of the addition (A+B'). The other input of the multiplexer is the 2's complement of that (A+B')'. (Where we're using ' to indicate the 2's complement operation rather than simple inversion)

That means you're calculating the 2's complement of the addition every time, even though you only need it sometimes. That kind of "wasted effort" is very common in digital logic.

\$\endgroup\$
2
  • \$\begingroup\$ But if I have 4 bits how do I link them to the 2-to-1 MUX? \$\endgroup\$ – P_M May 2 '20 at 15:05
  • \$\begingroup\$ You get a 4-bit 2-to-1 mux. Or you use four one-bit 2-to-1 muxes. \$\endgroup\$ – The Photon May 2 '20 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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