How Does an Adder/Subtractor Unit Handle Negative Inputs?

In summary, the Adder/Subtractor unit works by using XOR with the add/sub signal and Y to choose whether to add or subtract, and also adding 1 to the inverted bits. When subtracting negative numbers, the X input should be the bit pattern for the negative number, and 1 should be coupled into the carry-in of the LSB to effectively add 1.
  • #1
ECE
7
0
If two 4 bit numbers are being added in the Adder/Subtractor unit e.g. X and Y. Then according to my textbook it is written that the Add/Sub Unit is built in a way that the add/sub signal (which chooses whether to add/subtract) is XOR with Y (the position where the number that is to be complemented is entered). But what if the user wants to enters { -5-3 }.How will the add/sub unit work then? Should the X input be also XOR with another signal similar to add/sub?

-Thanks
 
Engineering news on Phys.org
  • #2
ECE said:
If two 4 bit numbers are being added in the Adder/Subtractor unit e.g. X and Y. Then according to my textbook it is written that the Add/Sub Unit is built in a way that the add/sub signal (which chooses whether to add/subtract) is XOR with Y (the position where the number that is to be complemented is entered).

but you must also add 1 to the inverted bits. you do that with this adder/subtractor by coupling in the same 1 that goes to the XORs (the add/subtract signal where add=0 and subtract=1) to the carry-in of the LSB (which is tied to 0 if you're adding).

But what if the user wants to enters { -5-3 }.How will the add/sub unit work then? Should the X input be also XOR with another signal similar to add/sub?

no, just put in for A the bit pattern for -5, which is the same bit pattern for an unsigned 4-bit number that is 16-5 or 11. so -5 is 1011 and you subtact 3 (0011) which gets complimented to 1100 and goes into your full-adder, but then you got to remember to couple in the 1 into the carry-in of the LSB (which effectively adds 1).

1011 + 1100 + 0001 = [1]1000

or -8 since the 1 that carries out falls off the edge.
 
  • #3


Yes, in the case of adding or subtracting negative numbers, the X input should also be XORed with a signal similar to the add/sub signal. This is because when performing subtraction, the second number is typically converted to its 2's complement form, which involves flipping all the bits and adding 1. So if we want to add a negative number, we need to first convert it to its 2's complement form and then add it to the first number. This can be achieved by XORing the X input with a signal that indicates whether the number is positive or negative. This way, the add/sub unit can properly perform the addition or subtraction operation.
 

What is an Adder and Subtractor Unit?

An Adder and Subtractor Unit is an electronic circuit used in digital systems to perform addition and subtraction operations on binary numbers.

What is the purpose of an Adder and Subtractor Unit?

The purpose of an Adder and Subtractor Unit is to perform mathematical operations, specifically addition and subtraction, on binary numbers in digital systems.

How does an Adder and Subtractor Unit work?

An Adder and Subtractor Unit works by using logic gates to manipulate the binary numbers. The inputs are the two numbers to be added or subtracted, and the outputs are the result of the operation.

What are the different types of Adder and Subtractor Units?

There are several types of Adder and Subtractor Units, including half adders, full adders, half subtractors, and full subtractors. These vary in the number of inputs and outputs they have, as well as the complexity of the circuit.

What are the applications of Adder and Subtractor Units?

Adder and Subtractor Units are used in a wide range of digital systems, including computers, calculators, and other electronic devices. They are essential for performing mathematical operations in these systems.

Similar threads

  • Electrical Engineering
Replies
4
Views
3K
  • Electrical Engineering
Replies
1
Views
968
  • Engineering and Comp Sci Homework Help
Replies
6
Views
17K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
5K
  • Electrical Engineering
Replies
1
Views
3K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
  • Special and General Relativity
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • General Math
Replies
1
Views
1K
Back
Top