27
CMPUT 329 - Computer Org anization and Architectu re II 1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

Embed Size (px)

Citation preview

Page 1: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

1

CMPUT329 - Fall 2002

Topic2: DeMorgan Laws

José Nelson Amaral

Page 2: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

2

Reading Assignment

Chapter 4: Sections 4.1.4, 4.1.5, 4.1.6, 4.2, 4.3.1, 4.3.2

Page 3: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

3

First DeMorgan’s Law

The complement of the sum is equal the product of the complements.

(X+Y)’ = X’Y’

XY

Z

X Y X+Y (X+Y)’ X’ Y’ X’Y’0 0 0 1 1 1 10 1 1 0 1 0 01 0 1 0 0 1 01 1 1 0 0 0 0

Z

Y

X

Page 4: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

4

First DeMorgan’s Law

The complement of the sum is equal the product of the complements.

(X+Y)’ = X’Y’

XY

Z

X Y X+Y (X+Y)’ X’ Y’ X’Y’0 0 0 1 1 1 10 1 1 0 1 0 01 0 1 0 0 1 01 1 1 0 0 0 0

Z

Y

X

Page 5: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

5

First DeMorgan’s Law

The complement of the sum is equal the product of the complements.

(X+Y)’ = X’Y’

XY

Z

X Y X+Y (X+Y)’ X’ Y’ X’Y’0 0 0 1 1 1 10 1 1 0 1 0 01 0 1 0 0 1 01 1 1 0 0 0 0

Z

Y

X

Page 6: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

6

First DeMorgan’s Law

The complement of the sum is equal the product of the complements.

(X+Y)’ = X’Y’

XY

Z

X Y X+Y (X+Y)’ X’ Y’ X’Y’0 0 0 1 1 1 10 1 1 0 1 0 01 0 1 0 0 1 01 1 1 0 0 0 0

Z

Y

X

Page 7: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

7

First DeMorgan’s Law

The complement of the sum is equal the product of the complements.

(X+Y)’ = X’Y’

XY

Z

X Y X+Y (X+Y)’ X’ Y’ X’Y’ 0 0 0 1 1 1 1 0 1 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0

Z

Y

X

Page 8: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

8

Second DeMorgan’s Law

The complement of the product is equal the sum of the complements.

(XY)’ = X’ + Y’

ZXY

X Y XY (XY)’ X’ Y’ X’ + Y’0 0 0 1 1 1 10 1 0 1 1 0 11 0 0 1 0 1 11 1 1 0 0 0 0

Z

Y

X

Page 9: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

9

NOR and NAND

Because these combination of gates are used often, thereare special symbols to represent them:

XY

Z XY

Z

ZXY

XY

Z

Page 10: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

10

DeMorgan’s Law (cont.)

The De Morgan’s laws generalize to n variables:

(X1 + X2 + X3 + ··· + Xn)’ = X1’X2’X3’ ··· Xn’

(X1X2X3 ··· Xn)’ = X1’ + X2’ + X3’ + ··· + Xn’

Page 11: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

11

DeMorgan’s Law (example)

Express the complement f’(w,x,y,z) of the following expression in a simplified form.

f(w,x,y,z) = wx(y’z + yz’)

f’(w,x,y,z) = w’ + x’ + (y’z +yz’)’

= w’ + x’ + (y’z)’(yz’)’

= w’ + x’ + (y + z’)(y’ + z)

= w’ + x’ + yy’ + yz + z’y’ + z’z

= w’ + x’ + 0 + yz + z’y’ + 0

= w’ + x’ + yz + y’z’

Page 12: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

12

Exclusive OR

X Y = XY’ + X’YX Y C0 0 00 1 11 0 11 1 0

If X=1 OR Y=1, butnot both of them, then C=1

XY

C

X 0 =

X 1 =

X X =

X X’ =

Commutative Law:X Y = Y X

Associative Law:(X Y) Z= X ( Y Z) = X Y Z

Distributive Law:X(Y Z) = XY XZ

X

X’

0

1

Page 13: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

13

Exclusive-OR (cont.)

Complement Law:(X Y)’ = X Y’ = X’ Y

X Y X’ Y’ XY (XY)’ XY’ X’Y0 0 1 1 0 1 1 10 1 1 0 1 0 0 01 0 0 1 1 0 0 01 1 0 0 0 1 1 1

Algebraic Proof:(X Y)’ = (XY’ + X’Y)’

= (XY’)’(X’Y)’= (X’ + Y)(X + Y’)= X’X + X’Y’ + XY + YY’= 0 + X’Y’ + XY + 0

= X’ Y= X’Y’ + XY= XY + X’Y’ = X Y’

Page 14: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

14

In-place Value Permutation

The following properties are valid:(XY)Y = X(XY)X= Y

X Y X1=XY Y1=X1Y X2=X1Y1 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1

Algebraic: (XY) Y = (XY’ + X’Y)Y’ + (XY’ + X’Y)’Y= XY’Y’ + X’YY’ + ((XY’)’(X’Y)’)Y= XY’ + 0 + ((X’+Y)•(X+Y’))Y= XY’ + X’XY + X’Y’Y +XYY + YY’Y= XY’ + 0 + 0 + XY + 0= X(Y’ + Y)= X•1= X

Page 15: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

15

Using In-place Value Permutation in Assembly

Can be used in assembly programming to exchange thevalue of two registers in place:

R1 R1R2R2 R1R2R1 R1R2

The In-place Value Permutation Property of the exclusive-OR:(XY)Y = X(XY)X= Y

If we do back substitution in the second and third operations,we will find out that (assuming R1=A and R2=B initially):R1 (A B)R2 (A B) B = AR1 (A B) A = BThus, if initially R1 = A and R2 = B, then after this sequence of operations, R1 = B and R2 = A.

Page 16: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

16

Equivalence Gate

(X Y) = XY + X’Y’X Y C0 0 10 1 01 0 01 1 1

If X=Y then C=1,otherwise C=0

(X Y) = (X Y)’

XY

C

Page 17: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

17

Positive and Negative Logic

Positive Logic: the higher voltage (+V) represents 1 and the lower voltage (0V) represents 0

Negative Logic: the higher voltage (+V) represents 0 and the lower voltage (0V) represents 1

Page 18: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

18

Positive and Negative Logic (example)

LogicGate

e2

e3

e1

eo

The same physical circuit implements different logicfunctions. The function implemented depends on the logic used to interpret the inputs and outputs.

e1 e2 e3 eo

0V 0V 0V 0V0V 0V +V 0V0V +V 0V 0V0V +V +V 0V+V 0V 0V 0V+V 0V +V 0V+V +V 0V 0V+V +V +V +V

+

Electric Voltages

e1 e2 e3 eo

0 0 0 00 0 1 00 1 0 00 1 1 01 0 0 01 0 1 01 1 0 01 1 1 1

+

Positive Logic

e1 e2 e3 eo

1 1 1 11 1 0 11 0 1 11 0 0 10 1 1 10 1 0 10 0 1 10 0 0 0

+

Negative Logic

Page 19: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

19

Duality

Any theorem or identity in switching algebraremains true if 0 and 1 are swapped and • and + are also swapped throughout.

Example:X + X • Y = X

X • X + Y = X (duality)X + Y = X (using idempotency)

what is wrong?

We must keep the operatorprecedence of the originalexpression, therefore:X + X • Y = XX • (X + Y) = X (duality)

Page 20: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

20

The Consensus Theorem

XY + X’Z + YZ = XY + X’Z

= XY + X’Z + (X + X’)YZ

= XY + X’Z + XYZ + X’YZ

= XY + XYZ + X’Z + X’YZ

= XY(1 + Z) + X’Z(1 + Y)

= XY·1 + X’Z·1

XY + X’Z + YZ = XY + X’Z + 1·YZ

= XY + X’Z

Page 21: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

21

Sum-of-Products (Minterms)

An expression is on a sum-of-products form if it isformed by the sum of products, and all the

products are formed by single variables only.

Examples:AB’ + CD’E + AC’E’ABC’ + DEFG + HA + B’ + C + D’E

The following expressions are not sum-of-products:(A+B)CD + EF(X + Y)(X + Z)

Each of the products in the sum-of-products form iscalled a minterm. Thus the form is also called

sum-of-minterms.

Page 22: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

22

Product-of-Sums (Maxterms)

Similarly, a product-of-sums is formedby the product of sums in which all the

sums are formed by single variables only.

Examples:(A + B’)(C + D’ + E)(A + C’ + E’)(A + B)(C + D +E)FAB’C(D’ + E)

The following expressions are not product-of-sums:(A+B)CD + EFA + B’ + C + D’E

Each of the sums in the product-of-sums form iscalled a maxterm. Thus the form is also called

product-of-maxterms.

Page 23: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

23

Building Practical Circuits

Problem: Design a logical circuit to automatically operatea car alarm. The manual for the alarm gives the following explanation for its operation.

“The alarm will go off if the alarm system is activated and any of the two doors or the trunk are open, or if the vibration sensor is activated and the key is not in the ignition.”

“The alarm will go off if the alarm system is activated and any of the two doors or the trunk are open, or if the vibration sensor is activated and the key is not in the ignition.”

AlarmActivatedDriverDoorOpenPassengerDoorOpenTrunkOpenVibrationKeyInIgnition

Inputs:

Page 24: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

24

Building Practical Circuits

“The alarm will go off if the alarm system is activated and any of the two doors or the trunk are open, or if the vibration sensor is activated and the key is not in the ignition.”

AlarmGoOff = AlarmActivated • (DriverDoorOpen + PassengerDoorOpen + TrunkOpen) + Vibration • (KeyInIgnition)’

AlarmActivatedDriverDoorOpenPassengerDoorOpenTrunkOpenVibrationKeyInIgnition

Inputs:

Page 25: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

25

Building Practical Circuits

AlarmGoOff = AlarmActivated • (DriverDoorOpen + PassengerDoorOpen + TrunkOpen) + Vibration • (KeyInIgnition)’

VibrationKeyInIgnition

AlarmGoOff

DriverDoorOpenPassengerDoorOpen

TrunkOpen

AlarmActivated

Page 26: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

26

Building a Circuit From a Truth Table

Design a logic circuit to implement a two bit adder. This circuithas three inputs (A, B, Cin), and two outputs (S, Cout). Theoutput S is one if the sum is one, i.e., the number of inputsequal one is odd. The carry out output is one if the sum producesa carry, i.e., two or more of the inputs are one.

Adder

Cin

Cout

SB

A

A B Cin S Cout0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1

+

Page 27: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2002 Topic2: DeMorgan Laws José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

27

Building a Circuit From a Truth Table

Adder

Cin

Cout

SB

A

A B Cin S Cout0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1

+

S = A’B’Cin + A’BCin’ + AB’Cin’ + ABCin

Cout = A’BCin + A B’Cin + ABCin’ + ABCin

= A’BCin + ABCin + AB’Cin + ABCin + ABCin’ + ABCin

= BCin + ACin + AB

= (A’ + A)BCin + (B’ + B)ACin + (Cin’ + Cin)AB

= 1·BCin + 1· ACin + 1· AB