1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

65
1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS SPECIFICATION OF ADDER MODULES FOR POSITIVE INTEGERS HALF-ADDER AND FULL-ADDER MODULES CARRY-RIPPLE AND CARRY-LOOKAHEAD ADDER MODULES NETWORKS OF ADDER MODULES REPRESENTATION OF SIGNED INTEGERS: 1. sign-and-magnitude 2. two’s-complement 3. ones’-complement ADDITION AND SUBTRACTION IN TWO’S COMPLEMENT ARITHMETIC-LOGIC UNITS (ALU) COMPARATOR MODULES AND NETWORKS MULTIPLICATION OF POSITIVE INTEGERS Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Transcript of 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

Page 1: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

1ARITHMETIC COMBINATIONAL MODULES AND NETWORKS

• SPECIFICATION OF ADDER MODULES FOR POSITIVE INTEGERS

• HALF-ADDER AND FULL-ADDER MODULES

• CARRY-RIPPLE AND CARRY-LOOKAHEAD ADDER MODULES

• NETWORKS OF ADDER MODULES

• REPRESENTATION OF SIGNED INTEGERS:

1. sign-and-magnitude

2. two’s-complement

3. ones’-complement

• ADDITION AND SUBTRACTION IN TWO’S COMPLEMENT

• ARITHMETIC-LOGIC UNITS (ALU)

• COMPARATOR MODULES AND NETWORKS

• MULTIPLICATION OF POSITIVE INTEGERS

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 2: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

2ADDITION OF POSITIVE INTEGERS

• CONVENTIONAL RADIX-2 NUMBER SYSTEM:

x = (xn−1, . . . , x0) ⇔ x, integer

x =n−1∑

i=0xi × 2i

• RANGE: 0 to 2n − 1

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 3: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

3ADDER MODULES FOR POSITIVE INTEGERS

ADDER

nn

n

yx

z

c incout

Figure 10.1: ADDER MODULE.

x + y + cin = 2ncout + z

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 4: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

4A HIGH-LEVEL SPECIFICATION OF ADDER MODULE

INPUTS: x = (xn−1, . . . , x0), xj ∈ {0, 1}y = (yn−1, . . . , y0), yj ∈ {0, 1}cin ∈ {0, 1}

OUTPUTS: z = (zn−1, . . . , z0), zj ∈ {0, 1}cout ∈ {0, 1}

FUNCTIONS: z = (x + y + cin) mod 2n

cout =

1 if (x + y + cin) ≥ 2n

0 otherwise

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 5: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

5EXAMPLE for n=5

x y cin z cout

12 14 1 (12 + 14 + 1) mod 32 = 27 0 because (12 + 14 + 1) < 3219 14 1 (19 + 14 + 1) mod 32 = 2 1 because (19 + 14 + 1) > 32

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 6: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

6CARRY-RIPPLE ADDER IMPLEMENTATION

Full Adder Full Adder Full Adder=cnc

out = cin

c0

y0

x0

z0

c1

yn-1

xn-1

zn-1

zi

yi

xi

ci+1 c

i

Figure 10.2: CARRY-RIPPLE ADDER MODULE.

• DELAY OF CARRY-RIPPLE ADDER

tp(net) = (n − 1)tc + max(tz, tc)

tc = Delay(ci → ci+1)

tz = Delay(ci → zi)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 7: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

7HIGH-LEVEL SPECIFICATION OF FULL-ADDER

xi + yi + ci = 2ci+1 + zi

INPUTS: xi, yi, ci ∈ {0, 1}OUTPUTS: zi, ci+1 ∈ {0, 1}

FUNCTION: zi = (xi + yi + ci) mod 2

ci+1 =

1 if (xi + yi + ci) ≥ 20 otherwise

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 8: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

8FULL-ADDER IMPLEMENTATION

xi yi ci ci+1 zi

0 0 0 0 00 0 1 0 10 1 0 0 10 1 1 1 01 0 0 0 11 0 1 1 01 1 0 1 01 1 1 1 1

zi = xiy′ic′i x′

iyic′i x′

iy′ici xiyici

ci+1 = xiyi xici yici

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 9: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

9FULL ADDER TWO-LEVEL IMPLEMENTATION

(a)ci

xi x’iyi y’i

x’i

y’i c’i

yi

xi

ci

x’i y’i

c’i

yixi

zi

xi

yi

xi

ci

ci

yi

ci+1

c’i+1

Figure 10.3: IMPLEMENTATIONS OF FULL-ADDER MODULE: a) TWO-LEVEL.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 10: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

10ALTERNATIVE IMPLEMENTATION

• ADDITION mod 2 → SUM IS 1 WHEN NUMBER OF 1’S IN INPUTS(including the carry-in) IS ODD:

zi = xi ⊕ yi ⊕ ci

• CARRY-OUT IS 1 WHEN (xi + yi = 2) or (xi + yi = 1 and ci = 1):

ci+1 = xiyi (xi ⊕ yi)ci

• INTERMEDIATE VARIABLES

PROPAGATE pi = xi ⊕ yi

GENERATE gi = xi · yi

• HALF-ADDER

xi yi gi pi

0 0 0 00 1 0 11 0 0 11 1 1 0

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 11: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

11IMPLEMENTATION WITH HALF-ADDERS

• FA EXPRESSIONS IN TERMS OF p′is, g′is and c′is

zi = pi ⊕ ci

ci+1 = gi pi · ci

(c)

zi

xiyi

ci

ci+1

pi

g’i

Half Adder (HA)HA

(b)

zi

xiyi

ci

ci+1

pi

gi

Figure 10.3: IMPLEMENTATIONS OF FULL-ADDER MODULE: b) MULTILEVEL GATE NETWORK WITH XORs, ANDs and OR;c) WITH XORs and NANDs.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 12: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

12WORST-CASE DELAY

Full Adder Full Adder Full Adder=cnc

out = cin

c0

y0

x0

z0

c1

yn-1

xn-1

zn-1

zi

yi

xi

ci+1 c

i

Figure 10.2: CARRY-RIPPLE ADDER MODULE.

• WORST-CASE DELAY tp = txor + 2(n − 1)tnand + max(2tnand, txor)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 13: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

13CHARACTERISTICS OF FULL-ADDER IN cmos FAMILY

Input [standard loads]ci 1.3xi 1.1yi 1.3

Size: 7 [equivalent gates]

From To Propagation delaystpLH tpHL

[ns] [ns]ci zi 0.43 + 0.03L 0.49 + 0.02Lxi zi 0.68 + 0.04L 0.74 + 0.02Lyi zi 0.68 + 0.04L 0.74 + 0.02Lci ci+1 0.36 + 0.04L 0.40 + 0.02Lxi ci+1 0.73 + 0.04L 0.71 + 0.02Lyi ci+1 0.37 + 0.04L 0.64 + 0.02L

L: load on the gate output

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 14: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

14CARRY-LOOKAHEAD ADDER IMPLEMENTATION

• FASTER IMPLEMENTATION

• ADDITION AS A TWO-STEP PROCESS:

1. DETERMINE THE VALUES OF ALL THE CARRIES

2. SIMULTANEOUSLY COMPUTE ALL THE RESULT BITS

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 15: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

15CARRY-LOOKAHEAD ADDER MODULE

Carry Generator

nn

n

Sum Generator

n n

n-1c

c noutc = c 0= inc

c1yx

z

x y

Figure 10.4: CARRY-LOOKAHEAD ADDER MODULE.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 16: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

16SWITCHING EXPRESSIONS

• INTERMEDIATE CARRIES:

ci+1 = gi pi · ci

BY SUBSTITUTION,

c1 = g0 p0c0

c2 = g1 p1c1

= g1 p1g0 p1p0c0

c3 = g2 p2c2

= g2 p2g1 p2p1g0 p2p1p0c0

c4 = g3 p3g2 p3p2g1 p3p2p1g0 p3p2p1p0c0

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 17: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

17

(a)

g3

p3

g2

p2

g1

p1

g0

p0

c0

c1

c2

c3

c4

p3 p

2

p1p

0

G

P

CLG-4

Figure 10.5: CARRY-LOOKAHEAD ADDER: a) 4-BIT CARRY-LOOKAHEAD GENERATOR WITH P and G OUTPUTS (clg-4).

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 18: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

18

CARRY LOOKAHEAD GENERATOR(CLG-4)

y0

x0

c4

yi

xi

y1

x1

y2

x2

y3

x3

g2

g1

c0G

P

g3

p3

p2

p1

g0

p0

p3

p2

p1

p0

c3

c2

c1

z3

z2

z1

z0

(b)

Figure 10.5: CARRY-LOOKAHEAD ADDER: b) 4-BIT MODULE (cla-4); (clg-4).

tp(x0 → c4) = tpg + tCLG−4

tp(c0 → c4) = tCLG−4

tp(x0 → P, G) = tpg + tCLG−4

tp(x0 → z3) = tpg + tCLG−4 + tXOR

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 19: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

19MODULE PROPAGATE AND GENERATE SIGNALS

P = 1: cin PROPAGATED BY THE MODULE

G = 1: cout = 1 GENERATED BY THE MODULE,IRRESPECTIVE OF cin

P =

1 if x + y = 24 − 10 otherwise

G =

1 if x + y ≥ 24

0 otherwise

cout = G P · cin

P = p3p2p1p0

G = g3 p3g2 p3p2g1 p3p2p1g0

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 20: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

20NETWORKS OF ADDER MODULES

ITERATIVE (CARRY-RIPPLE) ADDER NETWORK

x = (x(3), x(2), x(1), x(0))

x(3) = (x15, x14, x13, x12)

x(2) = (x11, x10, x9, x8)

x(1) = (x7, x6, x5, x4)

x(0) = (x3, x2, x1, x0)

wherex = 212x(3) + 28x(2) + 24x(1) + x(0)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 21: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

2116-BIT CARRY-RIPPLE ADDER

4-bit adder

44

4

cout= c16 4-bit

adder

4 4

4

4-bit adder

4 4

4

4-bit adder

4 4

4

x (0)x (1)x (2)x (3) y (0)y (1)y (2)y (3)

z (0)z (1)z (2)z (3)

cin = c0c4c8c12

Figure 10.6: 16-BIT CARRY-RIPPLE ADDER NETWORK USING 4-BIT ADDER MODULES.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 22: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

22CARRY-LOOKAHEAD ADDER NETWORK

2 2 2 2 2 2 2 24

z7

4

z6

4

z5

4

z4

4

z3

4

z2

4

z1

4

z0

CLA-4

x7

4

CLA-4

x6

4

CLA-4

x5

4

CLA-4

x4

4

CLA-4

x3

4

CLA-4

x2

4

CLA-4

x1

4

CLA-4

x0

4

G7 P7 G6 P6 G5 P5 G4 P4 G3 P3 G2 P2 G1 P1 G0 P0

c4c8c12c20c24c28

c32CLG-4 CLG-4

y7

4

y6

4

y5

4

y4

4

y3

4

y2

4

y1

4

y0

4

c4c8c12c20c24c28

c0

c16

c16

carries to CLA-4 modules

carries from CLG-4 modules

critical path

Figure 10.7: 32-BIT CARRY-LOOKAHEAD ADDER USING cla-4 AND clg-4 MODULES.

• PROPAGATION DELAY:

tp(net) = tPG + 2tclg−4 + tadd

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 23: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

23

CLA ADDER (cont.)

c4 = G0 P0c0

c8 = G1 P1G0 P1P0c0

c12 = G2 P2G1 P2P1G0 P2P1P0c0

c16 = G3 P3G2 P3P2G1 P3P2P1G0 P3P2P1P0c0

P0 = p3 · p2 · p1 · p0

G0 = g3 g2p3 g1p3p2 g0p3p2p1

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 24: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

24REPRESENTATION OF SIGNED INTEGERS AND BASIC OPERATIONS

• TWO COMMON REPRESENTATIONS:

- SIGN-AND-MAGNITUDE (SM)

- TRUE-AND-COMPLEMENT (TC)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 25: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

25

SIGN-AND-MAGNITUDE (SM) SYSTEM

• x REPRESENTED BY PAIR (xs, xm)

sign:

xs =

0 if x ≥ 01 if x ≤ 0

magnitude:xm

• RANGE OF SIGNED INTEGERS

total number of bits: n

sign: 1magnitude: n − 1

−(2n−1 − 1) ≤ x ≤ 2n−1 − 1

• TWO REPRESENTATIONS OF ZERO:

xs = 0, xm = 0 (positive zero)

xs = 1, xm = 0 (negative zero)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 26: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

26TWO’S-COMPLEMENT SYSTEM

• NO SEPARATION BETWEEN THE REPRESENTATION OF SIGNAND REPRESENTATION OF MAGNITUDE

• SIGNED INTEGER x REPRESENTED BY POSITIVE INTEGER xR

• MAP 2: BINARY REPRESENTATION OF xR

xR =n−1∑

i=0xi2

i , 0 ≤ xR ≤ 2n − 1

• MAP 1: TWO’S COMPLEMENT

xR = x mod 2n

BY DEFINITION OF mod, FOR |x| < 2n: equivalent to

xR =

x if x ≥ 02n − |x| if x < 0

FOR UNAMBIGUOUS SYMMETRICAL REPRESENTATION

|x|max ≤ 2n−1 − 1

x -4 -3 -2 -1 0 1 2 3

xR 4 5 6 7 0 1 2 3

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 27: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

27

Conventionalbinary code

Two’s-complementsystem

Map 1

Map 2

Signed integer

Positive integer

Bit-vector

x

xR

x

Figure 10.8: SIGNED INTEGER REPRESENTED BY POSITIVE INTEGER.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 28: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

28

01

2

3

4

5

6

78

9

10

11

12

13

14

15

0+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

True formsComplement forms

x

xR

Figure 10.9: TWO’S COMPLEMENT REPRESENTATION FOR n = 4.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 29: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

29MAPPING IN TWO’S-COMPLEMENT SYSTEM

x xR x

0 0 00...0001 1 00...0012 2 00...010- - - True forms- - - (positive)- - - xR = x

2n−1 − 1 2n−1 − 1 01...111−2n−1 2n−1 10...000

−(2n−1 − 1) 2n−1 + 1 10...001- - -- - - Complement forms- - - (negative)−2 2n − 2 11...110 xR = 2n − |x|−1 2n − 1 11...111

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 30: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

30EXAMPLE 10.2: MAPPINGS FOR −4 ≤ x ≤ 3

x xR x

3 3 0112 2 0101 1 0010 0 000-1 7 111-2 6 110-3 5 101-4 4 100

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 31: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

31CONVERSE MAPPING

x =

xR if xR ≤ 2n−1 − 1 (x ≥ 0)xR − 2n

if xR ≥ 2n−1 (x < 0)

IN TERMS OF BIT VECTOR (xn−1, xn−2, ..., x1, x0)

i) For xR < 2n−1, bit xn−1 is 0 and x ≥ 0.

x = xR = 0 × 2n−1 +n−2∑

i=0xi2

i

ii) For xR ≥ 2n−1 bit xn−1 is 1 and x < 0.

x = xR − 2n = (1 × 2n−1 +n−2∑

i=0xi2

i) − 2n = −1 × 2n−1 +n−2∑

i=0xi2

i

COMBINING BOTH CASES

x = −xn−12n−1 +

n−2∑

i=0xi2

i

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 32: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

32

x = −xn−12n−1 +

n−2∑

i=0xi2

i

8-BIT EXAMPLES:

x x

01000101 0 + 69 = 6911000101 −128 + 69 = −58

SIGN DETECTION:

x ≥ 0 if xn−1 = 0

x < 0 if xn−1 = 1

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 33: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

33ONES’-COMPLEMENT SYSTEM

xR = x mod C

ONES’-COMPLEMENT SYSTEM: C = 2n − 1

• the ones’-complement system symmetrical, with the range −(2n − 1) ≤ x ≤2n − 1;

• two representations for zero, namely xR = 0 and xR = 2n − 1;

• the sign also detected by the most-significant bit

x ≥ 0 if (xn−1 = 0) or (xR = 2n − 1)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 34: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

34MAPPING IN ONES’-COMPLEMENT SYSTEM

x xR x

0 0 00...0001 1 00...0012 2 00...010- - - True forms- - - (positive)- - - xR = x

2n−1 − 1 2n−1 − 1 01...111−(2n−1 − 1) 2n−1 10...000

- - -- - - Complement forms−2 2n − 3 11...101 (negative)−1 2n − 2 11...110 xR = 2n − 1 − |x|0 2n − 1 11...111

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 35: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

35ADDITION IN TWO’S COMPLEMENT SYSTEM

• TO GETz = x + y

COMPUTEzR = (xR + yR) mod 2n

CORRECT IF −2n−1 ≤ (x + y) ≤ 2n−1 − 1

• PROOF: CONSIDER(xR + yR) mod 2n

AND SHOW THAT IT CORRESPONDS TO zR

BY DEFINITION OF THE REPRESENTATION,

xR = x mod 2n and yR = y mod 2n

THEREFORE,

(xR + yR) mod 2n = (x mod 2n + y mod 2n) mod 2n

= (x + y) mod 2n = z mod 2n

BY DEFINITION OF REPRESENTATION

z mod 2n = zR

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 36: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

362’s COMPLEMENT ADDITION: A SUMMARY

1. ADD xR AND yR (use adder for positive operands)

2. PERFORM THE mod OPERATION

• DOES NOT DEPEND ON THE RELATIVE MAGNITUDES OF THE OPERANDSAND ON THEIR SIGNS (simpler than in S+M)

EXAMPLES OF ADDITION FOR C=64 and −32 ≤ x, y, z ≤ 31

Signed Representation Two’s-complement Signedoperands addition resultx y xR yR (xR + yR) mod 64 = zR z

13 9 13 9 22 mod 64 = 22 2213 -9 13 55 68 mod 64 = 4 4-13 9 51 9 60 mod 64 = 60 -4-13 -9 51 55 106 mod 64 = 42 -22

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 37: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

37THE mod OPERATION

• Let wR = xR + yR. Then

xR, yR < 2n ⇒ wR < 2 × 2n

zR = wR mod 2n =

wR if wR < 2n

wR − 2nif 2n ≤ wR < 2 × 2n

• Since wR < 2 × 2n

w = (wn, wn−1, ..., w0)

wR =

< 2nif wn = 0

≥ 2nif wn = 1

Case 1. wR < 2n. Then wR mod 2n = wR ⇔ (wn−1, ..., w0).

Case 2. wR ≥ 2n

wR mod 2n = wR − 2n ⇔ (1, wn−1, . . . , w0) − (1, 0, . . . , 0)

= (wn−1, . . . , w0)

• CONCLUSION: wR mod 2n = (wn−1, ..., w0)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 38: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

38• mod OPERATION PERFORMED BY DISCARDING MOST-SIGNIFICANT

BIT OF w

• 2’S COMPLEMENT ADDITION:

RESULT CORRESPONDS TO OUTPUT OF ADDER, DISCARDING THECARRY-OUT

z = ADD(x, y, 0)

ADDER

nn

n

yx

z

0cout

discard

Figure 10.10: TWO’S-COMPLEMENT ADDER MODULE.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 39: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

39EXAMPLES OF 2’S COMPLEMENT ADDITION

Bit-level Positive Signedcomputation representation values

n = 4 x = 1011 xR = 11 x = −5y = 0101 yR = 5 y = 5

w = 10000 wR = 16z = 0000 zR = 0 z = 0

n = 8 x = 11011010 xR = 218 x = −38y = 11110001 yR = 241 y = −15

w = 111001011 wR = 459z = 11001011 zR = 203 z = −53

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 40: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

40CHANGE OF SIGN IN TWO’S COMPLEMENT SYSTEM

• z = −x

zR = (2n − xR) mod 2n

x = 0: since z = −x = 0 we have zR = xR = 0. Moreover,

zR = (2n − 0) mod 2n = 0

x > 0: since z = −x is negative,

zR = 2n − |z| = 2n − |x|

Moreover, x is positive so that

xR = x

Substitute: zR = 2n − xR.

x < 0: since z = −x is positive,

zR = z = −x

Moreover, x is negative so that

xR = 2n − |x| = 2n + x

Substitute: zR = 2n − xR.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 41: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

41

CHANGE OF SIGN (cont.)

• DIRECT SUBTRACTION 2n − xR COMPLEX

EXAMPLE:

28 100000000xR 01011110

10100010

• INSTEAD, USE 2n = (2n − 1) + 1

zR = (2n − 1 − xR) + 1

• THE COMPLEMENT WITH RESPECT TO 2n − 1: COMPLEMENTEACH BIT OF x

xR = 17 01000163 − xR 111111 − 010001

101110

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 42: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

42CHANGE-OF-SIGN OPERATION

TWO-STEP OPERATION:

1. COMPLEMENT EACH BIT OF x denoted x′.

2. ADD 1 (set carry-in c0 = 1)

• DESCRIPTION:

z = ADD(x′, 0, 1)

EXAMPLE FOR n = 4, x = −3:

x 1101 x = −3x′ 00100 0000c0 1z 0011 z = 3

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 43: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

43SUBTRACTION IN TWO’S COMPLEMENT SYSTEM

• z = x − y = x + (−y)

zR = (xR + (2n − 1 − yR) + 1) mod 2n

• THE CORRESPONDING DESCRIPTION

z = ADDR(x, y′, 1)

EXAMPLE:

x 01100000y 00110001 y′ 11001110

1z 00101111

SUMMARY OF 2’S COMPLEMENT OPERATIONS

OPERATION 2’s COMPLEMENT SYSTEM

z = x + y z = ADD(x, y, 0)z = −x z = ADD(x′, 0, 1)

z = x − y z = ADD(x, y′, 1)

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 44: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

44OVERFLOW DETECTION IN ADDITION

• OVERFLOW – result exceeds most positive or negative representable integer

−2n−1 ≤ z ≤ 2n−1 − 1

- BOTH OPERANDS SAME SIGN, RESULT OPPOSITE SIGN

v = x′n−1y

′n−1zn−1 xn−1yn−1z

′n−1

x>0y>0z>0

x>0y>0z<0

x<0y<0z<0

x<0y<0z>0

Overflow

Overflow

0 2n

2n-1

Figure 10.11: OVERFLOW IN TWO’S-COMPLEMENT SYSTEM.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 45: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

45TWO’S COMPLEMENT ARITHMETIC UNIT

INPUTS: x = (xn−1, . . . , x0), xj ∈ {0, 1}

y = (yn−1, . . . , y0), yj ∈ {0, 1}

cin ∈ {0, 1}

F = (f2, f1, f0)

OUTPUTS: z = (zn−1, . . . , z0), zj ∈ {0, 1}

cout, sgn, zero, ovf ∈ {0, 1}

FUNCTIONS:

F Operation

001 add add z = x + y

011 sub subtract z = x − y

101 addc add with carry z = x + y + cin

110 cs change sign z = −x

010 inc increment z = x + 1

sgn = 1 if z < 0, 0 otherwise (the sign)

zero = 1 if z = 0, 0 otherwise

ovf = 1 if z overflows, 0 otherwise

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 46: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

46

xn-1 x0

Kx

COMPL X COMPL Y

ADDER

MUX0 1

Combinationalnetwork

n

n

n

ovf zero sgncout z

n n n

nn

(0...0)

c0

c0

cn

cn-1

x y

f2

f1

f0

Kx Ky KMX

cin

Kx Ky

KMX

n

zn-1

Figure 10.12: IMPLEMENTATION OF TWO’S-COMPLEMENT ARITHMETIC UNIT.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 47: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

47CONTROL OF TWO’S-COMPLEMENT ARITHMETIC OPERATIONS

• OPERATION IDENTIFIED BY BIT-VECTOR F = (f2, f1, f0)

• COMPLEMENT OPERATION a = compl(b, K):

ai =

bi if K = 0b′i if K = 1

Operation Op-code Control Signalsf2f1f0 z Kx Ky KMX

add 001 add(x, y, 0) 0 0 1sub 011 add(x, y′, 1) 0 1 1addc 101 add(x, y, cin) 0 0 1cs 110 add(x′, 0, 1) 1 d.c. 0inc 010 add(x, 0, 1) 0 d.c. 0

• CONTROL SIGNALS:

Kx = f2f1

Ky = f1

KMX = f0

c0 = f1 f2f0cin

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 48: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

48ALU MODULES AND NETWORKS

• ARITHMETIC-LOGIC UNIT

module realizing set of arithmetic and logic functions

• Why build ALUs?

1. Use in many different applications

2. alu modules used in processors: function selected by control unit

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 49: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

49TYPICAL EXAMPLE OF ALU

Control (S) Function

zero z = 0add z = (x + y + cin) mod 16sub z = (x + y′ + cin) mod 16exsub z = (x′ + y + cin) mod 16and z = x · yor z = x y

xor z = x ⊕ y

one z = 1111

a′ denotes the integer represented by vector a′

·, , and ⊕ are applied to the corresponding bits

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 50: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

504-bit ALU

44

4 - BIT ALU

x y

cin

P

G

z

S3

4

Figure 10.13: 4-bit ALU.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 51: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

51NETWORKS OF ALU MODULES

• MODULE HAS NO CARRY-OUT SIGNAL

– cannot be used directly in an iterative (carry-ripple) network

– carry-out signal implemented as

cout = G P · cin

– carry-skip network

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 52: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

5216-bit ALU

44

4 - BIT ALU

x 0 y 0

c 0

P0

G0

z 0

S3

4

44

4 - BIT ALU

3

4

P3

G3

z 3

x 3 y 3

44

4 - BIT ALU

c 8

z 2

3

4

y 2x 2

P2

G2

44

4 - BIT ALU

x 1 y 1

P1

G1

z 1

3

4

P3

G3

P2

G2

P1

G1

P0

G0

CLG-4

c 8

PG

c 4c12

c16

Figure 10.14: 16-bit alu.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 53: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

53COMPARATOR MODULES

• HIGH-LEVEL DESCRIPTION OF AN n-BIT COMPARATOR:

INPUTS: x = (xn−1, . . . , x0), xj ∈ {0, 1}y = (yn−1, . . . , y0), yj ∈ {0, 1}cin ∈ {G,E,S}

OUTPUT: z ∈ {G,E,S}

FUNCTION: z =

G if (x > y) or (x = y and cin = G)E if (x = y) and (cin = E)S if (x < y) or (x = y and cin = S)

x and y – the integers represented x and y

• IMPLEMENTATION OF 4-bit COMPARATOR MODULE

cin = (cGin, c

Ein, c

Sin) , cG

in, cEin, c

Sin ∈ {0, 1}

z = (zG, zE, zS) , zG, zE, zS ∈ {0, 1}

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 54: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

54

E1

S3

S2E3

G2E3

E3 S1E2

E3 G1E2

E3E2 S0E1

(b)

COMPARATORMODULE

(a)

44

x

y

G3

E3x3

y3

x2

y2

x1

y1

x0

y0

zG

zE

zS

c Gin

c Ein

c Sin

E2

E0

E3E2 G0E1

E3E2E1E0cGin

E3E2E1E0c Ein

E3E2E1E0c Sin

zS

zE

zG

c Gin

c Ein

c Sin

Figure 10.15: 4-BIT COMPARATOR MODULE: a) block diagram; b) gate-network implementation.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 55: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

55BINARY-LEVEL DESCRIPTION

Si = x′iyi

Ei = (xi ⊕ yi)′, i = 0, . . . , 3

Gi = xiy′i

zG = G3 + E3G2 + E3E2G1 + E3E2E1G0 + E3E2E1E0cGin

zE = E3E2E1E0cEin

zS = S3 + E3S2 + E3E2S1 + E3E2E1S0 + E3E2E1E0cSin

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 56: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

56ITERATIVE COMPARATOR NETWORK

x3 x2 x1 x0y3 y2 y1 y0

COMPARATORMODULE

COMPARATORMODULE

COMPARATORMODULE

COMPARATORMODULE

4 4

= 0

= 0

= 1

cinG

cinE

cinS

zG

z E

z S

Figure 10.16: 16-BIT ITERATIVE COMPARATOR NETWORK.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 57: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

57TREE COMPARATOR NETWORK

y1x3 y3

COMPARATORMODULE

x2 y2

COMPARATORMODULE

x1

COMPARATORMODULE

x0 y0

COMPARATORMODULE

4 4

010

g3 s3 g2 s2 g1 s1 g0 s0

COMPARATORMODULE

4 4

010

010

010

010

zG zE z S

zG zE z S zG zE z S zG zE z S zG zE z S

Figure 10.17: 16-BIT TREE COMPARATOR NETWORK.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 58: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

58

TREE COMPARATOR (cont.)

zG =

1 if g > s

0 otherwise

zE =

1 if g = s

0 otherwise

zS =

1 if g < s

0 otherwise

• g and s are the integers represented by the vectors g and s, respectively.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 59: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

59MULTIPLIERS

• n × m bits multiplier:

0 ≤ x ≤ 2n − 1 (the multiplicand)

0 ≤ y ≤ 2m − 1 (the multiplier),

0 ≤ z ≤ (2n − 1)(2m − 1) (the product).

• The high-level function:z = x × y

z = x(m−1

i=0yi2

i) =m−1

i=0xyi2

i

Since yi is either 0 or 1, we get

xyi =

0 if yi = 0x if yi = 1

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 60: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

60MULTIPLICATION BIT MATRIX

x7y0 x6y0 x5y0 x4y0 x3y0 x2y0 x1y0 x0y0

x7y1 x6y1 x5y1 x4y1 x3y1 x2y1 x1y1 x0y1

x7y2 x6y2 x5y2 x4y2 x3y2 x2y2 x1y2 x0y2

x7y3 x6y3 x5y3 x4y3 x3y3 x2y3 x1y3 x0y3

x7y4 x6y4 x5y4 x4y4 x3y4 x2y4 x1y4 x0y4

x7y5 x6y5 x5y5 x4y5 x3y5 x2y5 x1y5 x0y5

Multiplier implementation:

• m arrays of n and gates

• m − 1 n-bit adders

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 61: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

61

(a)

(b)

y 2

x7 x6 x5 x4 x3 x2 x1 x0

y0

y1

MH MF MF MF MF MF MF MH

MF MF MF MF MF MF MF MH

MF MF MF MF MF MF MF MH

MF MF MF MF MF MF MF MH

MF MF MF MF MF MF MF MH

y3

y4

y5

p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0p13

Module MF

Module MHsum_out

Half Adder

c_out

x_bit y_bit x_bit y_bit

OR

sum_out

Half Adder

c_out c_in

x_bit y_bit

sum_out

Full Adder

c_out c_in

sum_in

sum_in

Figure 10.18: IMPLEMENTATION OF AN 8 × 6 MULTIPLIER: a) PRIMITIVE MODULES; b) NETWORK.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 62: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

62MULTIPLIER DELAY

• delay of the buffer which connects signal y0 to the n and gates

• delay of the and gate

• delay of the adders

tadders = tc(n − 1) + ts + (tc + ts)(m − 2)

If ts = tc, we get

tadders = (n + 2(m − 2))ts = (n + 2m − 4)ts

FOR THE 8 × 6 CASE: tadders = (8 + 12 − 4)ts = 16ts

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 63: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

63EXAMPLE OF NETWORKS WITH STANDARD ARITHMETIC MODULES

Inputs: a[3], a[2], a[1], a[0], b[3], b[2], b[1], b[0] ∈ {0, ..., 216 − 1}e = (e3, e2, e1, e0) , ei ∈ {0, 1}

Outputs: c[3], c[2], c[1], c[0] ∈ {0, ..., 217 − 1}d ∈ {0, 1, 2, 3}f ∈ {0, 1}

Function:

f =

1 if at least one ej = 10 otherwise

, j = 0, 1, 2, 3

d =

i if ei is the highest priority event0 if no event occurred

c[i] =

a[i] + b[i] if ei is the highest priority event0 otherwise

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 64: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

64MODULAR IMPLEMENTATION

CONSISTS OF

• a priority encoder to determine the highest-priority event;

• an adder;

• two selectors (multiplexers) to select the corresponding inputs to theadder;

• a distributor (demultiplexer) to send the output of the adder to thecorresponding system output; and

• an or gate to determine whether at least one event has occurred.

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks

Page 65: 1 ARITHMETIC COMBINATIONAL MODULES AND NETWORKS ...

65

DISTRIBUTOR

PRIORITYENCODER

ADDER

SELECTOR SELECTOR

2

2

df

e3 e2 e1 e0

a[3] a[2] a[1] a[0] b[3] b[2] b[1] b[0]

c[3] c[2] c[1] c[0]

Figure 10.19: NETWORK IN EXAMPLE 10.5

Introduction to Digital Systems 10 – Arithmetic combinational modules and networks