lecture 4 combinational logic 2 - rom - arithmetic ...langer/273/4-slides.pdf · - rom - arithmetic...

31
lecture 4 Combinational logic 2 - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016

Upload: ngoduong

Post on 20-Mar-2019

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

lecture 4

Combinational logic 2

- ROM

- arithmetic circuits

- arithmetic logic unit (ALU)

January 20, 2016

Page 2: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Last lecture: truth tables, logic gates & circuits

Page 3: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Recall multiplexor (selector)

if S Y = Belse Y = A

We will use this several times later.

Page 4: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

"Read-only Memory"(leftover topic from last lecture)

address data

Sometimes we can think ofa circuit as a "hardwired"memory (read only).

Note: the order of the A1

A0 variables matters.

A1 A0 Y2 Y1 Y0

Page 5: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Recall: binary arithmetic

Notes:

- Co = 0

- A, B could represent signed or unsigned numbers

Page 6: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Let's build an "adder" circuit.

Page 7: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Half Adder

Page 8: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

full adder

Page 9: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Ripple Adder

If n = 32, then wecan have a longdelay as carriespropagate throughthe circuit. We'llreturn to this later.

Page 10: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

As I mentioned before.... the interpretation of the S bit string dependson whether the A and B bit strings are signed or unsigned.

However, the full adder circuit does not depend on whether A and Bare signed or unsigned.

Page 11: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Overflow

We still might want to know if we have "overflowed" :

e.g. - if the sum of two positive numbers yields a negative

- if the sum of two negative numbers yields a positive

How can we detect these two cases ? (see Exercises 2)

Page 12: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

TODO TODAY

- encoder

- decoder

- n-bit multiplexor

- fast adder

- ALU

Page 13: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Encoder

many bits code(few bits)

Page 14: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Encoder Example 1

This assumes only one button can be pressed at any time.

panel withfive buttons

Page 15: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

This allows two buttons to be pressed at the same time (andencodes the one with the highest index).

panel withfive buttons

Page 16: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

panel withten buttons

Encoder Example 2

display e.g. on adigital watch,calculator, etc.

Page 17: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

buttons lights

Each light Li is turned on (1) by some set of button presses.

Each button bk turns on (1) some set of lights.

Page 18: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Decoder

code word (in thisexample, itspecifies whichoutput is 1)

Page 19: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

2-bit multiplexor

Notation:

decoder

Page 20: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

More general example (2-bit multiplexor)

Selects from four n-bit inputs. For each Ai, Bi, Ci, Di, we replicatethe circuit on the previous slide, but use the same decoder circuit.

Page 21: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

n-bit multiplexor

We will next look at some examples of how multiplexors areused.

whichinput?

output2^ninputs

Page 22: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Recall the ripple adder.

The main problem is thatit is slow.

Page 23: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

How to speed up the adder ?

Instead of one 32 bit adder, think of two 16 bit adders.

We can compute the result of each, in half the time. (However, ifC16 = 1, then we have to wait for it to ripple through. )

Page 24: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Fast Adder

Tradeoffs: we chop the time in half (almost, why?) but it increases thenumber of gates by more than 50% (why?). Note we can repeat thisidea (recursion).

Page 25: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Subtraction

Invert bits and add 1.

Page 26: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,
Page 27: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Invert bits and add 1.

When Binvert is 1, thisadds 1 by setting C0 to 1.

Page 28: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,
Page 29: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Let's include a bitwise AND and OR.

Page 30: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Arithmetic Logic Unit (ALU)

Page 31: lecture 4 Combinational logic 2 - ROM - arithmetic ...langer/273/4-slides.pdf · - ROM - arithmetic circuits - arithmetic logic unit (ALU) January 20, 2016. Last lecture: truth tables,

Announcements

- 193 registered (172 seats in room)

- Quiz 1The solutions, grading scheme, and grades were posted yesterday.You should know this b/c you should be subscribed to news on mycourses. I will not be posting stuff on Facebook.

The TAs were instructed not to take off points for trivial errors if it wasclear you understood what you were doing. If your Quiz was notgraded according to this guideline, let me know by resubmitting it witha yellow sticky explaining the problem. Please do not make suchrequests for marginal judgment calls: similar to professionalsports ("the ruling on the field stands"). And, I reserve the rightto regrade the whole exam, if I disagree with you.