+ All Categories
Home > Documents > UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to...

UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to...

Date post: 08-Sep-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
104
CS64 Week 6 Lecture 1 Kyle Dewey
Transcript
Page 1: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

CS64 Week 6 Lecture 1Kyle Dewey

Page 2: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Overview• Tail call optimization

• Introduction to circuits

• Digital design: single bit adders

• Circuit minimization

• Boolean algebra

• Karnaugh maps

• Exploiting don’t cares

Page 3: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

More Recursion• What’s special about the following

recursive function?

int recFac(int n, int accum) { if (n == 0) { return accum; } else { return recFac(n - 1, n * accum); }}

Page 4: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

More Recursion• What’s special about the following recursive

function?

• It is tail recursive - with the right optimization, uses constant stack space

• We can do this in assembly - tail_recursive_factorial.asm

int recFac(int n, int accum) { if (n == 0) { return accum; } else { return recFac(n - 1, n * accum); }}

Page 5: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Dispelling the Magic: Circuits

Page 6: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Why Binary?

• Very convenient for a circuit

• Two possible states: on and off

• 0 and 1 correspond to on and off

Page 7: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Relationship to Bitwise Operations

• You’re already familiar with bitwise OR, AND, XOR, and NOT

• These same operations are fundamental to circuits

• Basic building blocks for more complex things

Page 8: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Single Bits

• For the moment, we will deal only with individual bits

• Later, we’ll see this isn’t actually that restrictive

Page 9: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Operations on Single Bits: AND

0

00

0

10

1

00

1

11

Page 10: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Operations on Single Bits: OR

00

001

1

10

1 11

1

Page 11: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Operations on Single Bits: XOR

00

001

1

10

111

0

Page 12: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Operations on Single Bits: NOT

0 1 1 0

Page 13: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Recall: Addition

Page 14: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Addition with Single Bits

10

+0--1

10

+1--0

11

+0--0

11

+1--1

00

+0--0

00

+1--1

01

+0--1

01

+1--0

Carry: 1 Carry: 1 Carry: 1

Carry: 1

Page 15: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

In Summary

Single Bit Adder

First OperandBit

Second OperandBit

Input CarryBit

Result Bit Output CarryBit

Page 16: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

• How can we adapt this to add multi-digit binary numbers together?

Single Bit Adder

First OperandBit

Second OperandBit

Input CarryBit

Result Bit Output CarryBit

Page 17: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Putting it Together

Single Bit Adder

First OperandBit

Second OperandBit

Input CarryBit

Result Bit Output CarryBit

Page 18: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Putting it Together

+

I1 I2

CI CO

R

Page 19: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Recall: Single Bit Adders

+

I1 I2

CI CO

R

Page 20: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Stringing them Together

+

A0 B0

0

R0

+

R1

+ C

R2

For two three-bit numbers, A and B, resulting ina three-bit result R

A1 B1 A2 B2

Page 21: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

+

0 0

0 0

0

+

0 1

0 0

1

+

1 0

0 0

1

+

1 1

0 1

0

+

0 0

1 0

1

+

0 1

1 1

0

+

1 0

1 1

0

+

1 1

1 1

1

Page 22: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

As a Truth Table

+

I1 I2

CI CO

R

CI I1 I2 CO R

0 0 0 0 0

0 0 1 0 1

0 1 0 0 1

0 1 1 1 0

1 0 0 0 1

1 0 1 1 0

1 1 0 1 0

1 1 1 1 1

Page 23: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

As a Truth Table

+

I1 I2

CI CO

R

CI I1 I2 CO R

0 0 0 0 0

0 0 1 0 1

0 1 0 0 1

0 1 1 1 0

1 0 0 0 1

1 0 1 1 0

1 1 0 1 0

1 1 1 1 1

Question: how can this be turned into a

circuit?

Page 24: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of Products

• Variables: A, B, C...

• Negation of a variable: A, B, C...

Page 25: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of Products

• Another way to look at OR: sum (+)

• Another way to look at AND: multiplication (*)

A + B

A * B AB

Page 26: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of Products Example

A B O

0 0 0

0 1 1

1 0 1

1 1 0

Page 27: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of Products Example

A B O

0 0 0

0 1 1

1 0 1

1 1 0

Page 28: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of Products Example

A B O

0 0 0

0 1 1

1 0 1

1 1 0

O = A*B

Page 29: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of Products Example

A B O

0 0 0

0 1 1

1 0 1

1 1 0

O = A*B + A*B

Page 30: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of ProductsCI I1 I2 CO R

0 0 0 0 0

0 0 1 0 1

0 1 0 0 1

0 1 1 1 0

1 0 0 0 1

1 0 1 1 0

1 1 0 1 0

1 1 1 1 1

Question: What wouldthe sum of products

look like for this table?(Note: need oneequation for each

output.)

Page 31: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Sum of ProductsCI I1 I2 CO R

0 0 0 0 0

0 0 1 0 1

0 1 0 0 1

0 1 1 1 0

1 0 0 0 1

1 0 1 1 0

1 1 0 1 0

1 1 1 1 1

Question: What wouldthe sum of products

look like for this table?(Note: need oneequation for each

output.)

Answer in thepresenter notes.

Page 32: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

In-Class Example: Shift Left by 1

Page 33: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Circuit Minimization

Page 34: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Motivation

• Unnecessarily large programs: bad

• Unnecessarily large circuits: Very Bad™

• Why?

Page 35: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Motivation

• Unnecessarily large programs: bad

• Unnecessarily large circuits: Very Bad™

• Why?

• Bigger circuits = bigger chips = higher cost (non-linear too!)

• Longer circuits = more time needed to move electrons through = slower

Page 36: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Simplification

• Real-world formulas can often be simplified, according to algebraic rules

• How might we simplify the following?

R = A*B + !A*B

Page 37: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Simplification

R = A*B + !A*B

R = B(A + !A)

R = B(true)

R = B

• Real-world formulas can often be simplified, according to algebraic rules

• How might we simplify the following?

Page 38: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Simplification Trick

• Look for products that differ only in one variable

• One product has the original variable (A)

• The other product has the other variable (!A)

R = A*B + !A*B

Page 39: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 1

!ABCD + ABCD + !AB!CD + AB!CD

Page 40: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 1

!ABCD + ABCD + !AB!CD + AB!CD

BCD(A + !A) + !AB!CD + AB!CD

Page 41: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 1

!ABCD + ABCD + !AB!CD + AB!CD

BCD(A + !A) + !AB!CD + AB!CD

BCD + !AB!CD + AB!CD

Page 42: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 1

!ABCD + ABCD + !AB!CD + AB!CD

BCD(A + !A) + !AB!CD + AB!CD

BCD + B!CD(!A + A)

BCD + !AB!CD + AB!CD

Page 43: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 1

!ABCD + ABCD + !AB!CD + AB!CD

BCD(A + !A) + !AB!CD + AB!CD

BCD + B!CD(!A + A)

BCD + !AB!CD + AB!CD

BCD + B!CD

Page 44: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 1

!ABCD + ABCD + !AB!CD + AB!CD

BCD(A + !A) + !AB!CD + AB!CD

BCD + B!CD(!A + A)

BCD + !AB!CD + AB!CD

BCD + B!CD

BD(C + !C)

Page 45: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 1

!ABCD + ABCD + !AB!CD + AB!CD

BCD(A + !A) + !AB!CD + AB!CD

BCD + B!CD(!A + A)

BCD + !AB!CD + AB!CD

BCD + B!CD

BD(C + !C)BD

Page 46: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 2!A!BC + A!B!C + !ABC + !AB!C + A!BC

Page 47: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 2!A!BC + A!B!C + !ABC + !AB!C + A!BC

!A!BC + A!BC + A!B!C + !ABC + !AB!C

Page 48: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 2!A!BC + A!B!C + !ABC + !AB!C + A!BC

!A!BC + A!BC + A!B!C + !ABC + !AB!C

!BC(A + !A) + A!B!C + !ABC + !AB!C

Page 49: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 2!A!BC + A!B!C + !ABC + !AB!C + A!BC

!A!BC + A!BC + A!B!C + !ABC + !AB!C

!BC(A + !A) + A!B!C + !ABC + !AB!C

!BC + A!B!C + !ABC + !AB!C

Page 50: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 2!A!BC + A!B!C + !ABC + !AB!C + A!BC

!A!BC + A!BC + A!B!C + !ABC + !AB!C

!BC(A + !A) + A!B!C + !ABC + !AB!C

!BC + A!B!C + !ABC + !AB!C

!BC + A!B!C + !AB(C + !C)

Page 51: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Additional Example 2!A!BC + A!B!C + !ABC + !AB!C + A!BC

!A!BC + A!BC + A!B!C + !ABC + !AB!C

!BC(A + !A) + A!B!C + !ABC + !AB!C

!BC + A!B!C + !ABC + !AB!C

!BC + A!B!C + !AB(C + !C)

!BC + A!B!C + !AB

Page 52: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Scaling Up

• Performing this sort of algebraic manipulation by hand can be tricky

• We can use Karnaugh maps to make it immediately apparent as to what can be simplified

Page 53: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ExampleR = A*B + !A*B

Page 54: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ExampleR = A*B + !A*B

A B O

0 0 0

0 1 1

1 0 0

1 1 1

Page 55: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ExampleR = A*B + !A*B

A B O

0 0 0

0 1 1

1 0 0

1 1 1

AB

0

1

0 1

0

0

1

1

Page 56: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ExampleR = A*B + !A*B

A B O

0 0 0

0 1 1

1 0 0

1 1 1

AB

0

1

0 1

0

0

1

1

Page 57: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ExampleR = A*B + !A*B

A B O

0 0 0

0 1 1

1 0 0

1 1 1

AB

0

1

0 1

0

0

1

1

Page 58: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ExampleR = A*B + !A*B

A B O

0 0 0

0 1 1

1 0 0

1 1 1

AB

0

1

0 1

0

0

1

1

R = B

Page 59: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Three Variables• We can scale this up to three variables, by

combining two variables on one axis

• The combined axis must be arranged such that only one bit changes per position

ABC

0

1

00 01

?

11 10

?

?

?

?

?

?

?

Page 60: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Three Variable Example

Page 61: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!BC + !ABC + A!BC + ABC

Page 62: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!BC + !ABC + A!BC + ABC

A B C R

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

Page 63: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!BC + !ABC + A!BC + ABC

A B C R

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

ABC

0

1

00 01

0

11 10

0

1

1

1

1

0

0

Page 64: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!BC + !ABC + A!BC + ABC

A B C R

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

ABC

0

1

00 01

0

11 10

0

1

1

1

1

0

0

Page 65: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!BC + !ABC + A!BC + ABC

A B C R

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

ABC

0

1

00 01

0

11 10

0

1

1

1

1

0

0

R = C

Page 66: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Another Three Variable Example

Page 67: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!B!C + !A!BC + !ABC +!AB!C + A!B!C + AB!C

Page 68: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

A B C R

0 0 0 1

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 0

R = !A!B!C + !A!BC + !ABC +!AB!C + A!B!C + AB!C

Page 69: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ABC

0

1

00 01

1

11 10

1

1

0

1

0

1

1

R = !A!B!C + !A!BC + !ABC +!AB!C + A!B!C + AB!C

A B C R

0 0 0 1

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 0

Page 70: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ABC

0

1

00 01 11 10

R = !A!B!C + !A!BC + !ABC +!AB!C + A!B!C + AB!C

A B C R

0 0 0 1

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 0

1

1

1

0

1

0

1

1

Page 71: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ABC

0

1

00 01 11 10

R = !A!B!C + !A!BC + !ABC +!AB!C + A!B!C + AB!C

A B C R

0 0 0 1

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 0

1

1

1

0

1

0

1

1

Page 72: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ABC

0

1

00 01 11 10

R = !A!B!C + !A!BC + !ABC +!AB!C + A!B!C + AB!C

A B C R

0 0 0 1

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 0

1

1

1

0

1

0

1

1

Page 73: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

ABC

0

1

00 01 11 10

R = !A!B!C + !A!BC + !ABC +!AB!C + A!B!C + AB!C

A B C R

0 0 0 1

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 0

1

1

1

0

1

0

1

1

R =!A + !C

Page 74: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Four Variable Example

Page 75: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!B!C!D + !A!B!CD + !A!BC!D +!ABC!D + A!B!C!D + A!B!CD + A!BC!D

Page 76: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!B!C!D + !A!B!CD + !A!BC!D +!ABC!D + A!B!C!D + A!B!CD + A!BC!D

ABCD

00 01 11 10

1

0

1

0

0

0

1

1

00

01

11

10

0

1

0

1

0

0

0

1

Page 77: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!B!C!D + !A!B!CD + !A!BC!D +!ABC!D + A!B!C!D + A!B!CD + A!BC!D

ABCD

00 01 11 10

1

0

1

0

0

0

1

1

00

01

11

10

0

1

0

1

0

0

0

1

Page 78: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!B!C!D + !A!B!CD + !A!BC!D +!ABC!D + A!B!C!D + A!B!CD + A!BC!D

ABCD

00 01 11 10

1

0

1

0

0

0

1

1

00

01

11

10

0

1

0

1

0

0

0

1

R =!B!C

Page 79: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!B!C!D + !A!B!CD + !A!BC!D +!ABC!D + A!B!C!D + A!B!CD + A!BC!D

ABCD

00 01 11 10

1

0

1

0

0

0

1

1

00

01

11

10

0

1

0

1

0

0

0

1

R =!B!C + !B!D

Page 80: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

R = !A!B!C!D + !A!B!CD + !A!BC!D +!ABC!D + A!B!C!D + A!B!CD + A!BC!D

ABCD

00 01 11 10

1

0

1

0

0

0

1

1

00

01

11

10

0

1

0

1

0

0

0

1

R =!B!C + !B!D + !AC!D

Page 81: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

K-Map Rules in Summary (1)

• Groups can contain only 1s

• Only 1s in adjacent groups are allowed (no diagonals)

• The number of 1s in a group must be a power of two (1, 2, 4, 8...)

• The groups must be as large as legally possible

Page 82: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

• All 1s must belong to a group, even if it’s a group of one element

• Overlapping groups are permitted

• Wrapping around the map is permitted

• Use the fewest number of groups possible

K-Map Rules in Summary (2)

Page 83: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Revisiting Problem!A!BC + A!B!C + !ABC + !AB!C + A!BC

Page 84: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Revisiting ProblemR = !A!BC + A!B!C + !ABC + !AB!C + A!BC

A B C R

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 0

1 1 1 0

Page 85: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Revisiting ProblemR = !A!BC + A!B!C + !ABC + !AB!C + A!BC

ABC

0

1

00 01

0

11 10

1

1

1

1

0

1

0

A B C R

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 0

1 1 1 0

Page 86: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Revisiting ProblemR = !A!BC + A!B!C + !ABC + !AB!C + A!BC

ABC

0

1

00 01

0

11 10

1

1

1

1

0

1

0

A B C R

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 0

1 1 1 0

R = !AC

Page 87: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Revisiting ProblemR = !A!BC + A!B!C + !ABC + !AB!C + A!BC

ABC

0

1

00 01

0

11 10

1

1

1

1

0

1

0

A B C R

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 0

1 1 1 0

R = !AC + A!B

Page 88: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Revisiting ProblemR = !A!BC + A!B!C + !ABC + !AB!C + A!BC

ABC

0

1

00 01

0

11 10

1

1

1

1

0

1

0

A B C R

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 0

1 1 1 0

R = !AC + A!B + !AB!C

Page 89: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Difference

• Algebraic solution: !BC + A!B!C + !AB

• K-map solution: !AC + A!B + !AB!C

• Question: why might these differ?

Page 90: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Difference

• Algebraic solution: !BC + A!B!C + !AB

• K-map solution: !AC + A!B + !AB!C

• Question: why might these differ?

• Both are minimal, in that they have the fewest number of products possible

• Can be multiple minimal solutions

Page 91: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Difference

• Algebraic solution: !BC + A!B!C + !AB

• K-map solution: !AC + A!B + !AB!C

• Question: why might these differ?

• Both are minimal, in that they have the fewest number of products possible

• Can be multiple minimal solutions

Page 92: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Difference

ABC

0

1

00 01

0

11 10

1

1

1

1

0

1

0

K-map solution: !AC + A!B + !AB!CAlgebraic solution: !BC + A!B!C + !AB

Page 93: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Difference

ABC

0

1

00 01

0

11 10

1

1

1

1

0

1

0

K-map solution: !BC + A!B!C + !ABAlgebraic solution: !BC + A!B!C + !AB

Page 94: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Exploiting Don’t Cares in K-Maps

Page 95: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Don’t Cares

• Occasionally, a circuit’s output will be unspecified on a given input

• Occurs when an input’s value is invalid

• In these situations, we say the output is a don’t care, marked as an X in a truth table

Page 96: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example: Binary Coded Decimal

• Occasionally, it is convenient to represent decimal numbers directly in binary, using 4-bits per decimal digit

• For example, a digital display

Page 97: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example: Binary Coded Decimal

• Not all binary values map to decimal digits

Binary Decimal0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

Binary Decimal1000 8

1001 9

1010 X

1011 X

1100 X

1101 X

1110 X

1111 X

Page 98: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Significance

• Recall that in a K-map, we can only group 1s

• Because the value of a don’t care is irrelevant, we can treat it as a 1 if it is convenient to do so (or a 0 if that would be more convenient)

Page 99: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example• A circuit that calculates if the binary coded

decimal input % 2 == 0

Page 100: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example• A circuit that calculates if the binary coded

decimal input % 2 == 0

I3 I2 I1 I0 R0 0 0 0 1

0 0 0 1 0

0 0 1 0 1

0 0 1 1 0

0 1 0 0 1

0 1 0 1 0

0 1 1 0 1

0 1 1 1 0

I3 I2 I1 I0 R1 0 0 0 1

1 0 0 1 0

1 0 1 0 X

1 0 1 1 X

1 1 0 0 X

1 1 0 1 X

1 1 1 0 X

1 1 1 1 X

Page 101: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example

I3I2

I1I000 01 11 10

1

1

0

0

1

1

0

0

00

01

11

10

X

1

X

0

X

X

X

X

As a K-map

Page 102: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example

I3I2

I1I000 01 11 10

1

1

0

0

1

1

0

0

00

01

11

10

X

1

X

0

X

X

X

X

If we don’t exploit don’t cares...

Page 103: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example

I3I2

I1I000 01 11 10

1

1

0

0

1

1

0

0

00

01

11

10

X

1

X

0

X

X

X

X

If we do exploit don’t cares...

Page 104: UCSB Computer Science - CS64 Week 6 Lecture 1Overview • Tail call optimization • Introduction to circuits • Digital design: single bit adders • Circuit minimization • Boolean

Example

I3I2

I1I000 01 11 10

1

1

0

0

1

1

0

0

00

01

11

10

X

1

X

0

X

X

X

X

If we do exploit don’t cares...R = !I1!I0 + I1I0


Recommended