Revision Problems 2

78
Revision Problems 2 Prof. Sin-Min Lee Department of Computer Science

description

Lecture 26. Revision Problems 2. Prof. Sin-Min Lee Department of Computer Science. Example of combinational and sequential logic. Combinational: input A, B wait for clock edge observe C wait for another clock edge observe C again: will stay the same Sequential: input A, B - PowerPoint PPT Presentation

Transcript of Revision Problems 2

Page 1: Revision  Problems 2

Revision Problems 2

Prof. Sin-Min Lee

Department of Computer Science

Page 2: Revision  Problems 2

B

AC

Clock

Example of combinational and sequential logic

• Combinational:– input A, B– wait for clock edge– observe C– wait for another clock edge– observe C again: will stay the same

• Sequential:– input A, B– wait for clock edge– observe C– wait for another clock edge– observe C again: may be different

Page 3: Revision  Problems 2

Basically

• Combinational:– No internal state (or memory or history or

whatever you want to call it)– Output depends only on input

• Sequential:– Output depends on internal state– Probably not going to be on this midterm since

formal lecture on it started last Thursday.

Page 4: Revision  Problems 2
Page 5: Revision  Problems 2
Page 6: Revision  Problems 2
Page 7: Revision  Problems 2

Some commonly used components• Decoders: n inputs, 2n outputs.

– the inputs are used to select which output is turned on. At any time exactly one output is on.

• Multiplexors: 2n inputs, n selection bits, 1 output.– the selection bits determine which input will

become the output.

• Adder: 2n inputs, 2n outputs. – Computer Arithmetic.

Page 8: Revision  Problems 2

Multiplexer

• “Selects” binary information from one of many input lines and directs it to a single output line.

• Also known as the “selector” circuit,• Selection is controlled by a particular set of inputs

lines whose # depends on the # of the data input lines.

• For a 2n-to-1 multiplexer, there are 2n data input lines and n selection lines whose bit combination determines which input is selected.

Page 9: Revision  Problems 2

MUX

2n DataInputs

DataOutput

InputSelect

n

Enable

Page 10: Revision  Problems 2

Remember the 2 – 4 Decoder?

S1

S0

Sel(3)

Sel(2)

Sel(1)

Sel(0)

Mutually Exclusive(Only one O/P asserted

at any time

Page 11: Revision  Problems 2

4 to 1 MUX

2 - 4 Decoder

Control

DataFlow

D3:D0

4

Sel(3:0)

4

S1:S0

2

Dout

Page 12: Revision  Problems 2

4-to-1 MUX (Gate level)

Three of these signal inputs will always be 0.

The other will depend on the data value selected

Control Section

Page 13: Revision  Problems 2

• Until now, we have examined single-bit data selected by a MUX. What if we want to select m-bit data/words? Combine MUX blocks in parallel with common select and enable signals

• Example: Construct a logic circuit that selects between 2 sets of 4-bit inputs (see next slide for solution).

Multiplexer (cont.)

Page 14: Revision  Problems 2

Example: Quad 2-to-1 MUX

• Uses four 4-to-1 MUXs with common select (S) and enable (E).

• Select line chooses between Ai’s and Bi’s. The selected four-wire digital signal is sent to the Yi’s

• Enable line turns MUX on and off (E=1 is on).

Page 15: Revision  Problems 2

Implementing Boolean functions with Multiplexers

• Any Boolean function of n variables can be implemented using a 2n-1-to-1 multiplexer. A MUX is basically a decoder with outputs ORed together, hence this isn’t surprising.

• The SELECT signals generate the minterms of the function.

• The data inputs identify which minterms are to be combined with an OR.

Page 16: Revision  Problems 2

Example

•F(X,Y,Z) = X’Y’Z + X’YZ’ + XYZ’ + XYZ = Σm(1,2,6,7)•There are n=3 inputs, thus we need a 2222-to-1 MUX-to-1 MUX•The first n-1 (=2) inputs serve as the selection linesThe first n-1 (=2) inputs serve as the selection lines

Page 17: Revision  Problems 2

Efficient Method for implementing Boolean functions

• For an n-variable function (e.g., f(A,B,C,D)):– Need a 2n-1 line MUX with n-1 select lines.– Enumerate function as a truth table with consistent ordering

of variables (e.g., A,B,C,D)– Attach the most significant n-1 variables to the n-1 select

lines (e.g., A,B,C)– Examine pairs of adjacent rows (only the least significant

variable differs, e.g., D=0 and D=1).– Determine whether the function output for the (A,B,C,0) and

(A,B,C,1) combination is (0,0), (0,1), (1,0), or (1,1).– Attach 0, D, D’, or 1 to the data input corresponding to

(A,B,C) respectively.

Page 18: Revision  Problems 2

Another Example

• Consider F(A,B,C) = m(1,3,5,6). We can implement this function using a 4-to-1 MUX as follows.

• The index is ABC. Apply A and B to the S1 and S0 selection inputs of the MUX (A is most sig, S1 is most sig.)

• Enumerate function in a truth table.

Page 19: Revision  Problems 2

MUX Example (cont.)

A B C F

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 1

1 1 1 0

When A=B=0, F=CWhen A=B=0, F=C

When A=0, B=1, When A=0, B=1, F=CF=CWhen A=1, B=0, When A=1, B=0, F=CF=CWhen A=B=1, When A=B=1, F=C’F=C’

Page 20: Revision  Problems 2

MUX implementation of F(A,B,C) = m(1,3,5,6)

AA

BB

CC

CC

CC

C’C’

FF

Page 21: Revision  Problems 2

1 input Decoder

DecoderI O1

O0

Treat I as a 1 bit integer i. The ith output will be turned on (Oi=1), the other one off.

Page 22: Revision  Problems 2

1 input Decoder

I O1

O0

Page 23: Revision  Problems 2

2 input Decoder

Decoder

I0

I1

O0

O2

O1

O3

Treat I0I1 as a 2 bit integer i. The ith output will be turned on (Oi=1), all the others off.

Page 24: Revision  Problems 2

I1I0

O0 = !I0 && !I1

2 input Decoder

O1 = !I0 && I1

O2 = I0 && !I1

O3 = I0 && I1

Page 25: Revision  Problems 2

3 Input Decoder

Decoder

I0

I1

O0

O2

O1

O3

O4

O6

O5

O7

I2

Page 26: Revision  Problems 2

3-Decoder Partial ImplementationI2I1

O0

I0

O1

. . .

Page 27: Revision  Problems 2

2 Input Multiplexor

Inputs: I0 and I1

Selector: S

Output: O

If S is a 0: O=I0

If S is a 1: O=I1

Mux

I0

I1

O

S

Page 28: Revision  Problems 2

2-Mux Logic Design

I1I0S

O

I0 && !S

I1 && S

Page 29: Revision  Problems 2

4 Input Multiplexor

Inputs: I0 I1 I2 I3

Selectors: S0 S1

Output: O Mux

I0

I2

O

S0

S0 S1 O

0 0 I0

0 1 I1

1 0 I2

1 1 I3

I1

I3

S1

Page 30: Revision  Problems 2

One Possible 4-Mux

2-Decoder

I0

I1

I2

I3

S0

S1O

Page 31: Revision  Problems 2

Adder

• We want to build a box that can add two 32 bit numbers.– Assume 2s complement representation

• We can start by building a 1 bit adder.

Page 32: Revision  Problems 2

Addition

• We need to build a 1 bit adder– compute binary addition of 2 bits.

• We already know that the result is 2 bits.

A B O0 O1

0 0 0 0

0 1 0 1

1 0 0 1

1 1 1 0

A

+ B

O0 O1

This is addition!

Page 33: Revision  Problems 2

One Implementation

AB O0

!AB

A!B

O1

A && B

(!A && B) || (A && !B)

Page 34: Revision  Problems 2

Binary addition and our adder

What we really want is something that can be used to implement the binary addition algorithm. – O0 is the carry– O1 is the sum

01001+ 01101

10110

11 Carry

Page 35: Revision  Problems 2

What about the second column?

• We are adding 3 bits– new bit is the carry from the first column.– The output is still 2 bits, a sum and a carry

01001+ 01101

10110

11 Carry

Page 36: Revision  Problems 2

Truth Table for Addition

A B Carry

In

Carry

Out

Sum

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 37: Revision  Problems 2

1 bit adder (3 inputs!)

• We can come up with a logic design:

Carry Out = (A&&B) || (A&&CarryIn) || (B&&CarryIn)

Sum = (!A && !B && CarryIn) ||

(!A && B && !CarryIn) ||

( A && !B && !CarryIn) ||

( A && B && CarryIn)

Page 38: Revision  Problems 2

New Component: 1 Bit Adder

adderA

B

Carry In

Carry Out

Sum

Page 39: Revision  Problems 2

Building a 32 bit Adder

• 64 inputs

• 32 bit output

A0 A1 … A31 B0 B1 … B31

……

R0 R1 … R31

Result

Page 40: Revision  Problems 2

4 Bit Ripple Carry Adder

adder

A0

C0

S0

B0

adder

A1

S1

B1

adder

A2

S2

B2

adder

A3

S3

B3

C1C2C3

A3A2A1A0

+ B3B2B1B0

S3S2S1S0

C3 C2 C1 C0

Page 41: Revision  Problems 2

4 Bit Ripple Carry Adder

adder 0adder

adder

adder

1100

0100

0011

+ 0010

1

adder0

1

0

0

adder1

0

1

1

adder0

1

0

0

adder0

0

Page 42: Revision  Problems 2

Subtraction

• Compute A-B as A + (-B-1) + 1

• -B-1 is just all the bits of B inverted.

• Add the +1 by setting C0 to 1

Page 43: Revision  Problems 2

Subtraction

adder 1adder

adder

adder

1010

0101

- 0011

0

adder1

0

1

adder0

1

0

adder1

0

0

adder1

0

0011

B inverted

Page 44: Revision  Problems 2
Page 45: Revision  Problems 2
Page 46: Revision  Problems 2
Page 47: Revision  Problems 2

Two’s Complement Numbers

• Nothing is different!– This is the advantage of using 2’s complement

representation.

• Overflow:– For addition: sign of the result is different than

the sign of the operands (and they have the same sign).

Page 48: Revision  Problems 2

-3 + 7

adder 0adder

adder

adder

1011

1110

1101

+ 0111

0

adder1

0

1

0

adder1

0

1

1

adder1

1

1

0

adder1

0

Page 49: Revision  Problems 2

-3 + -7

adder 0adder

adder

adder

1011

1001

1101

+ 1001

0

adder0

0

1

1

adder1

1

0

1

adder0

1

0

0

adder1

0

Overflow!

Page 50: Revision  Problems 2

Ripple Carry Timing

• All the adders are actually operating all the time (they are just combinational circuits).

• We wait long enough (until the last carry has been computed) and then pay attention to the complete answer.

• It is likely that there are intermediate values that are wrong!

Page 51: Revision  Problems 2

Carry Look-ahead

• Compute the carry bits right away.– As a function of the inputs A and B.

• Not possible for a large adder (32 bit), but realistic for a 4 bit adder.

Page 52: Revision  Problems 2

4 Bit Carry Look-ahead

adderadder

adder

adder

0011

+ 0010

Carry Generator

1100

1100

0100

0100 0

1

adder0

1

0

0

adder1

1

1

adder0

1

0

0

adder0

0

Carry Generator

0

0

Page 53: Revision  Problems 2
Page 54: Revision  Problems 2
Page 55: Revision  Problems 2
Page 56: Revision  Problems 2
Page 57: Revision  Problems 2
Page 58: Revision  Problems 2
Page 59: Revision  Problems 2
Page 60: Revision  Problems 2
Page 61: Revision  Problems 2
Page 62: Revision  Problems 2
Page 63: Revision  Problems 2
Page 64: Revision  Problems 2
Page 65: Revision  Problems 2
Page 66: Revision  Problems 2
Page 67: Revision  Problems 2
Page 68: Revision  Problems 2
Page 69: Revision  Problems 2
Page 70: Revision  Problems 2

Combinational circuit implementation using MUX

• We can use Multiplexers to express Boolean functions also.

• Expressing Boolean functions as MUXs is more efficient than as decoders.

• First n-1 variables of the function used as selection inputs; last variable used as data inputs.

• If last variable is called Z, then each data input has to be Z, Z’, 0, or 1.

Page 71: Revision  Problems 2
Page 72: Revision  Problems 2
Page 73: Revision  Problems 2
Page 74: Revision  Problems 2

Karnaugh Map Method of Multiplexer Implementation

Consider the function:

A is taken to be the data variable and B,C to be the select variables.

Page 75: Revision  Problems 2

Example of MUX combo circuit • F(X,Y,Z) = m(1,2,6,7)

Page 76: Revision  Problems 2
Page 77: Revision  Problems 2
Page 78: Revision  Problems 2