Digital Building Blocks - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L05.pdf ·...

29
CS031 Lecture 5 1 CS31 Pascal Van Hentenryck Digital Building Blocks

Transcript of Digital Building Blocks - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L05.pdf ·...

CS031 Lecture 5 1

CS31 Pascal Van Hentenryck

Digital Building Blocks

CS031 Lecture 5 2

Overview

Digital Building Blocks •  Decoders and Multiplexers •  ALU (arithmetic and logic unit) •  ROM

ALU •  This is the brawn of the

computer

ROM •  Useful for implementing the

control

CS031 Lecture 5 3

The Big Picture

compiler

computer

processor

datapath

control

memory

input

output

compiler

computer

processor

datapath

control

memory

input

output

CS031 Lecture 5 4

Abstraction Hierarchy

Programming Language

Assembly Language

Machine Language

Sequential Circuit

Combinational Circuit

Binary Value

Voltage

Programming Language

Assembly Language

Machine Language

Sequential Circuit

Combinational Circuit

Binary Value

Voltage

CS031 Lecture 5 5

Two Building Blocks

Decoders •  n inputs / 2n outputs •  Given the inputs, select a unique

output •  Particularly useful for implementing

memories

Multiplexers (selectors) •  2n data inputs / n selection inputs / 1

output •  The output is the data input selected

by the selection input •  Particularly useful for implementing

ALU and various other pieces of the machine

CS031 Lecture 5 6

Decoders

x

y

Turn binary “coded” quantities into one unit vector for every possible value.

do

d1

d2

d3

CS031 Lecture 5 7

Decoders

Turn binary “coded” quantities into one unit vector for every possible value.

x y d0 d1 d2 d3 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 1

Look at (x, y) as a binary number

The decoder •  assign d2*x+y to 1 •  all the others to zero

CS031 Lecture 5 8

Decoders

Turn binary “coded” quantities into one unit vector for every possible value.

x y d0 d1 d2 d3 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 1

CS031 Lecture 5 9

More Decoders

•  Decoders can be in any size

•  n is always 2m

•  two types of decoders: a single output 1 or a single output is 0

m by n decoder

n output m input

CS031 Lecture 5 10

Multiplexers Choose a particular input to pass through as specified by values on the selection (or address) lines.

Essentially a switch in hardware Output = l2x+y

I0

I1

I2

I3

output

y x

selector

CS031 Lecture 5 11

Multiplexers Choose a particular input to pass through as specified by values on the selection (or address) lines.

S1 S2 O 0 0 I0 0 1 I1 1 0 I2 1 1 I3

CS031 Lecture 5 12

Multiplexers Choose a particular input to pass through as specified by values on the selection (or address) lines.

What is inside a multiplexer? •  can you see it?

CS031 Lecture 5 13

Multiplexers Choose a particular input to pass through as specified by values on the selection (or address) lines.

What is inside a multiplexer? •  can you see it?

CS031 Lecture 5 14

1-bit ALU

1-bit ALU with and and or

a

b

operation

result

Add addition to this ALU now.

CS031 Lecture 5 15

1-bit ALU

CS031 Lecture 5 16

32-bit ALU

CS031 Lecture 5 17

32-bit ALU

Alu0

Alu1

Alu31

Oper ation

a0

b0

a1 b1

Carr yIn

a31 b31

CS031 Lecture 5 18

32-bit ALU

Include subtraction •  Add the negative version of b

How to obtain the negative version •  Invert each bit •  Add 1

How do to that simply •  Generalize a bit •  Use a simple trick

This shows why 2’s complement is a good representation

CS031 Lecture 5 19

1-bit ALU (Revisited)

CS031 Lecture 5 20

32-bit ALU

CS031 Lecture 4 21

ALU (Absolutely Lazy Unit)

Possible Modes

Operation 0: R = A + B

Operation 1: R = A – B

Operation 2: R = A and B

Operation 3: R = A or B

A B

R

function

Binv Cin

O1 O0

CS031 Lecture 5 22

Controlling the ALU

O1 O0 Binv Cin A + B 0 0 0 0 A – B 0 1 1 1 A ^ B 1 0 0 x A v B 1 1 0 x

(Look Ma! I can build an ALU)

CS031 Lecture 5 23

Implementing a Logic Function

Three main possibilities •  Specific circuit •  ROM •  PLA

Specific Circuit •  when there is a lot of structure (the

Karnaugh map, remember?)

ROM •  when there is almost no structure

PLA •  in between

CS031 Lecture 5 24

Read Only Memory (ROM) Map addresses to fixed values

a1 a2 a3 O 0 0 0 V1 0 0 1 V2 0 1 0 V3 0 1 1 V4 1 0 0 V5 1 0 1 V6 1 1 0 V7 1 1 1 V8

CS031 Lecture 5 25

Modern ROMs

Local outputs are associated with each pulldown

The local outputs are equal to their corresponding inputs

The output is the logical and of the local outputs

“Pulldown

input 1

input 3

input 2 loc.output 1

loc.output 2

Output

1

CS031 Lecture 5 26

Modern ROMs

Modern ROMs are organized around •  a decoder •  a multiplexer •  an array of pulldowns

2 n x2 m decoder

n address

arr a y of pulldo w ns

bits

m u ltiple x e r m address

bits

Output

CS031 Lecture 5 27

Example (stupid, I agree)

Assume that I need a ROM to store the prime numbers from 0 to 63.

Given an integer (between 0 and 63), build a circuit that returns 1 if the number is prime and 0 otherwise.

The integer is given as a sequence of bits

A5 A4 A3 A2 A1 A0

We use an array of 8 by 8

CS031 Lecture 5 28

Storing Primes Put a pulldown where you want a 0.

If you want more than one bit of output, just use more ROM circuits in parallel with different stored functions.

decoder

multiplexer

Output Address

1 2 3 4 5 6

7

7

6

5

4

3

2

1

0

A2 A1 A0

A3 A4 A5

0

CS031 Lecture 5 29

Not Chaining Adders Can we speed this up?

FAFAFAFA0x0y0y2x2y2x2y1x1S0S1S2S3C

FA

FA

FA

FA

0 x0 y0

x1

x2

x3

y1

y2

y3

S0

S1

S2

S3

C