Digital Logic Design · Lab 4 · read before the labAll labsGo to the lab →

Subtraction, borrow by borrow.

Subtracting is adding in disguise. Build the subtractor from gates first, then see why an adder with inverted inputs does the same job.

01

Borrows

0 - 1 cannot be done in one column: the column borrows 1 from the next higher column, where it is worth 2, so 0 - 1 = 1 with a borrow out. The next column must then pay the borrow back. Click the bits:

Borrow in1100
A
B
D = A - B0011

9 - 6 = 3. Final borrow 0: no borrow, the result is positive.

02

Half subtractor

DifferenceD = A'B + AB' = A ⊕ Bthe same XOR as the half adder sum
BorrowBo = A' . Ba borrow only for 0 - 1
03

Full subtractor

DifferenceD = A ⊕ B ⊕ Bintwo XOR gates
BorrowBo = (A ⊕ B)' Bin + A'Btwo inverters, two AND gates, one OR gate

Like the full adder, it is two half subtractors and an OR gate. Chain four of them, borrow out to borrow in, and you have a 4-bit subtractor (Task 3).

04

Two's complement

A - B

= A + (B' + 1). Invert every bit of B and add one more: that is the two's complement of B.

Cin = 1

The +1 comes in through the first carry in of the adder: wire Cin (pin 7) to +5 V.

Cout

With this method Cout = 1 means A is at least B (no borrow); Cout = 0 means the result is negative.

05

Adder and subtractor in one

An XOR gate is a controlled inverter: B ⊕ 0 = B and B ⊕ 1 = B'. Put one XOR on every B line, drive the other XOR input and Cin from one mode switch M, and the 74283 adds when M = 0 and subtracts when M = 1.

742834-bit binary full adder1S12B13A14S05A06B07Cin8GND9Cout10S311B312A313S214A215B216VCC

Hold the chip with its notch on the left. Pin 1 is at the bottom left, the pins count up to the right, then continue along the top from right to left. Most 14 pin chips have VCC on pin 14 and GND on pin 7, but not all: check every new chip.

06

Check yourself

Q1What are D and Bo of a half subtractor for A = 0, B = 1?

D = 1 and Bo = 1.

Q2What is the two’s complement of 0101?

1010 + 1 = 1011.

Q3In the full adder subtractor, 3 - 5 gives Cout = ?

0: the result is negative and the sum pins show 1110 (two’s complement of 2).

Q4Why are XOR gates used in the adder and subtractor?

They pass B unchanged when M = 0 and invert it when M = 1.

I am ready, go to the lab →