2-2 Addition Combined with Logical Operations

We assume the reader is familiar with the elementary identities of ordinary algebra and Boolean algebra. Below is a selection of similar identities involving addition and subtraction combined with logical operations:

a.       graphics/02icon14.gif

b.       graphics/02icon15.gif

c.       graphics/02icon16.gif

d.       graphics/02icon17.gif

e.       graphics/02icon18.gif

f.        graphics/02icon19.gif

g.       graphics/02icon20.gif

h.       graphics/02icon21.gif

i.         graphics/02icon22.gif

j.         graphics/02icon23.gif

k.       graphics/02icon24.gif

l.         graphics/02icon25.gif

m.     graphics/02icon26.gif

n.       graphics/02icon27.gif

o.       graphics/02icon28.gif

p.       graphics/02icon29.gif

q.       graphics/02icon30.gif

r.        graphics/02icon31.gif

s.       graphics/02icon32.gif

t.        graphics/02icon33.gif

u.       graphics/02icon34.gif

v.       graphics/02icon35.gif

Equation (d) may be applied to itself repeatedly, giving -??span class=docemphbolditalic1>x = x + 2, and so on. Similarly, from (e) we have -??x = x - 2. So we can add or subtract any constant, using only the two forms of complementation.

Equation (f) is the dual of (j), where (j) is the well-known relation that shows how to build a subtracter from an adder.

Equations (g) and (h) are from HAKMEM memo [HAK, item 23]. Equation (g) forms a sum by first computing the sum with carries ignored (x y) and then adding in the carries. Equation (h) is simply modifying the addition operands so that the combination 0 + 1 never occurs at any bit position; it is replaced with 1 + 0.

It can be shown that in the ordinary addition of binary numbers with each bit independently equally likely to be 0 or 1, a carry occurs at each position with probability about 0.5. However, for an adder built by preconditioning the inputs using (g), the probability is about 0.25. This observation is probably not of value in building an adder, because for that purpose the important characteristic is the maximum number of logic circuits the carry must pass through, and using (g) reduces the number of stages the carry propagates through by only one.

Equations (k) and (l) are duals of (g) and (h), for subtraction. That is, (k) has the interpretation of first forming the difference ignoring the borrows (x y), and then subtracting the borrows. Similarly, Equation (l) is simply modifying the subtraction operands so that the combination 1 - 1 never occurs at any bit position; it is replaced with 0 - 0.

Equation (n) shows how to implement exclusive or in only three instructions on a basic RISC. Using only and-or-not logic requires four instructions ((x | y) & ?x & y)). Similarly, (u) and (v) show how to implement and and or in three other elementary instructions, whereas using DeMorgan's laws requires four.