Skip to content
BetterDL

Adder/subtractor

Also called: add/sub, add/subtract circuit, adder-subtractor circuit

A ripple-carry adder with an XOR on every B input and one control line M: M = 0 computes A + B, and M = 1 computes A + B' + 1 = A − B.

An adder/subtractor is one circuit that can add or subtract, chosen by a single mode line M. It's built from:

When M = 0, the XORs pass B unchanged and C0 = 0, so the output is A + B.

When M = 1, the XORs invert B and C0 = 1, so the output is A + + 1. In twos complement, + 1 is −B, so that's A − B (twos complement subtraction).

The neat part is that the +1 costs nothing: the adder already has a carry-in, and M simply drives it. An n-bit adder/subtractor needs only n extra XOR gates.

Reading the results:

  • Unsigned: after an add, a carry out of 1 means overflow. After a subtract, carry-out 1 means no borrow (A ≥ B).
  • Signed: V = Cₙ ⊕ Cₙ₋₁ detects signed overflow for both operations, because it looks at what the adder really adds.

Since bit 0 receives C0 = M, it needs a full adder, not a half adder.

MA1A0B1B0S1S0C2

Worked examples

Example

1011 − 0100 (11 − 4) with M = 1

The XORs invert B and the carry-in adds 1.

  1. 1.

    B after the XORs: 0100 → 1011.

  2. 2.

    C0 = M = 1.

  3. 3.

    Add: 11 + 11 + 1 = 23 = 1 0111.

  4. 4.

    Keep 4 bits: 0111 = 7 = 11 − 4. The carry-out 1 means no borrow.

Example

The same inputs with M = 0

The XORs pass B unchanged and C0 = 0, so the circuit computes 1011 + 0100 = 1111 = 15 = 11 + 4.

Common mistakes

  • Driving the XORs with M but leaving C0 = 0. Every difference comes out one too small.

  • Using a half adder in bit 0. Bit 0 needs a carry-in for the +1.

  • Reading the carry-out after a subtraction the wrong way round. Here 1 means no borrow.

Practice Adder/subtractor

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Adder/subtractor is taught in Adders and ALUs.