Lesson 2. The full adder and 4 bits: the carry runs through the digits

In pictures

After this lesson a display will show the sum of two 4-bit numbers — from 0 + 0 to 15 + 15 = 30. We build the full adder of one digit FA and put four such digits in a chain — that is ADDER4.


2.1. The idea: column addition

Binary numbers are added the same way as decimal ones at school — in columns, right to left. Each column adds three digits: the two digits of the numbers and the carry from the column on the right. The result is a digit of the sum and a carry onwards:

  • A, B — the digits of the numbers, CI (carry in) — the carry that came from the right;
  • S — the sum digit of this column, CO (carry out) — the carry into the next column.

Three bits are added by two half adders: the first does A + B, the second adds CI to their sum. A carry onwards is needed if at least one of them gave one: CO = c1 OR c2. Both cannot give a carry at once — the sum of three bits is at most 11 (three).

A=1B=1CI=1HAA + Bs1=0c1=1HAs1 + CIS = 1c2=0ORCO = 11 + 1 + 1 = 11 (three): sum 1, carry 1
The full adder FA for A = 1, B = 1, CI = 1. The first half adder adds A + B = 10 (s1 = 0, carry c1 = 1), the second adds CI: 0 + 1 = 1. The carry out CO = c1 OR c2 = 1.

Four FA in a row are four columns. The CO of each digit goes to the CI of the next, so the carry runs from right to left through all the digits, like a wave. The top carry CO is the fifth digit of the sum: 15 + 15 = 30 does not fit in 4 bits.

FAA0=1B0=1S0=0c1=1FAA1=1B1=0S1=0c2=1FAA2=1B2=0S2=0c3=1FAA3=0B3=1S3=0CI=0CO=10111 + 1001 = 1 0000 (7 + 9 = 16): the carry is born in digit 0 and runs to the end
ADDER4 — four FA in a chain, the lowest digit on the right, as in column addition. The CO of each digit goes to the CI of the next. In the 7 + 9 example the carry is born in digit 0 and runs left through every digit; the top carry CO is the fifth digit of the sum.

2.2. Building

The same project as lesson 1. Delete the lesson 1 setup (switches A, B, the HA chip on the canvas, lamps); keep Power/Ground with the labels VCC/GND. The HA and OR chips stay in the library. Everything on labels (wires are fine too).

If you have FA from the "A Watch and a Game from Gates" kit — use it, the pins are the same: A, B, CI → S, CO.

Step 1. FA — the full adder

Adds three bits: A, B and the carry from the lower digit CI. First A + B with a half adder, then the carry is added to the sum with the second half adder; the carry out CO is set if either of them gave a carry.

PartPinLabel
Input portoutA
Input portoutB
Input portoutCI
HA (1st)A
B
S
C
A
B
s1
c1
HA (2nd)A
B
S
C
s1
CI
S
c2
ORI0
I1
O0
c1
c2
CO
Output portinS
Output portinCO

Ctrl+G → name FA. Chip pins: inputs A, B, CI, outputs S, CO.

Step 2. ADDER4 — four digits

The carry runs from the lowest digit to the highest: the CO of each FA goes to the CI of the next.

PartPinLabel
Input portoutA0
Input portoutA1
Input portoutA2
Input portoutA3
Input portoutB0
Input portoutB1
Input portoutB2
Input portoutB3
Input portoutCI
FA (digit 0)A
B
CI
S
CO
A0
B0
CI
S0
c1
FA (digit 1)A
B
CI
S
CO
A1
B1
c1
S1
c2
FA (digit 2)A
B
CI
S
CO
A2
B2
c2
S2
c3
FA (digit 3)A
B
CI
S
CO
A3
B3
c3
S3
CO
Output portinS0
Output portinS1
Output portinS2
Output portinS3
Output portinCO

Ctrl+G → name ADDER4. Pins: inputs A0–A3, B0–B3, CI; outputs S0–S3, CO.

Step 3. Canvas: switches, adder, displays

PartPinLabel
InputoutA0
InputoutA1
InputoutA2
InputoutA3
InputoutB0
InputoutB1
InputoutB2
InputoutB3
ADDER4A0
A1
A2
A3
B0
B1
B2
B3
CI
S0
S1
S2
S3
CO
A0
A1
A2
A3
B0
B1
B2
B3
GND
S0
S1
S2
S3
S4
Display⚙width 4, DEC, bus A
Display⚙width 4, DEC, bus B
Display⚙width 8, DEC, bus S

On the canvas the carry CO is the label S4: it is the fifth digit of the sum, so display S shows numbers up to 30. CI is on GND for now (the carry into the lowest digit = 0) — in lesson 3 it becomes the subtract switch.

2.3. Check

ASwitches A3…A0BSwitches B3…B0Display S
30011401007
701119100116carry: S4 is lit
15111115111130maximum
00000000000

In the "Switches" columns the top switch (A3) is on the left and A0 on the right; 1 — on, 0 — off.

If only the high digits of the sum are wrong, check that the carry goes c1 → c2 → c3 and that the CO of the last FA is on the chip's CO.


Lesson 2 paste (Cmd+I)

Needs HA and OR from lesson 1.

# Lesson 2 — the full adder FA and the 4-bit adder ADDER4.chip FA {  portIn(A)  portIn(B)  portIn(CI)  portOut(S)  portOut(CO)  HA(A, B, s1, c1)  HA(s1, CI, S, c2)  OR(c1, c2, CO)} chip ADDER4 {  portIn(A0)  portIn(A1)  portIn(A2)  portIn(A3)  portIn(B0)  portIn(B1)  portIn(B2)  portIn(B3)  portIn(CI)  portOut(S0)  portOut(S1)  portOut(S2)  portOut(S3)  portOut(CO)  FA(A0, B0, CI, S0, c1)  FA(A1, B1, c1, S1, c2)  FA(A2, B2, c2, S2, c3)  FA(A3, B3, c3, S3, CO)} input(A0)input(A1)input(A2)input(A3)input(B0)input(B1)input(B2)input(B3)ADDER4(A0=A0, A1=A1, A2=A2, A3=A3, B0=B0, B1=B1, B2=B2, B3=B3, CI=GND, S0=S0, S1=S1, S2=S2, S3=S3, CO=S4)

¿No te sale? Algo no funciona →