A 4-bit binary adder-subtractor can perform both addition and subtraction operations using binary numbers. It typically involves using an XOR gate to handle subtraction. Let me explain the basic design:
Key Concept
- Addition is done directly using binary addition rules.
- Subtraction is achieved by converting the second operand to its two’s complement and then performing binary addition.
How It Works
- Adder-Subtractor Setup:
- You have two 4-bit binary numbers, say A (A₃A₂A₁A₀) and B (B₃B₂B₁B₀).
- You need a control input, Mode (M), which determines whether the operation is addition or subtraction:
- M = 0: Perform addition (A + B).
- M = 1: Perform subtraction (A – B).
- Two’s Complement for Subtraction:
- To subtract (A – B), you take the two’s complement of B and then add it to A.
- The two’s complement of B is found by inverting all bits of B and adding 1.
- Using XOR gates:
- Each bit of B is passed through an XOR gate, with the Mode (M) as the control input.
- When M = 0 (for addition), the XOR gate will output B as it is.
- When M = 1 (for subtraction), the XOR gate will output the inverted bits of B (forming the two’s complement of B).
- The result of this XOR operation is then added to A.
- Each bit of B is passed through an XOR gate, with the Mode (M) as the control input.
- Carry-in for Addition/Subtraction:
- The adder needs to handle the carry bits during the addition. Additionally, if subtracting, there is an initial carry-in (C₀ = 1) due to the two’s complement.
Logic Block Diagram:
- Inputs:
- A (A₃, A₂, A₁, A₀)
- B (B₃, B₂, B₁, B₀)
- Mode (M)
- Outputs:
- Sum/Result (S₃, S₂, S₁, S₀)
- Carry-out (C₄)
- Operations:
- For each bit, pass B through an XOR gate with M as the control input.
- Use a full adder for each bit of A and the modified B (using XOR) to generate the sum and carry.
Example:
For A = 1011 (11 in decimal) and B = 0101 (5 in decimal):
- Addition (M = 0):
- A + B = 1011 + 0101 = 10000 (16 in decimal).
- Subtraction (M = 1):
- Take two’s complement of B (0101), which is 1011.
- A – B = 1011 + 1011 = 10110 (6 in decimal, ignoring the carry-out).
This structure is the basic idea behind a 4-bit adder-subtractor. The key is the XOR gate for switching between addition and subtraction, and the full adder logic for performing the operation.