Introduction to Digital Logic -...

41
© Egemen K. Çetinkaya Introduction to Digital Logic Missouri S&T University CPE 2210 Multipliers/Dividers Egemen K. Çetinkaya Department of Electrical & Computer Engineering Missouri University of Science and Technology [email protected] http://web.mst.edu/~cetinkayae/teaching/CPE2210Spring2018 2 March 2018 rev. 18.0 © 20142018 Egemen K. Çetinkaya

Transcript of Introduction to Digital Logic -...

Page 1: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Introduction to Digital LogicMissouri S&T University CPE 2210

Multipliers/Dividers

Egemen K. Çetinkaya

Department of Electrical & Computer Engineering

Missouri University of Science and Technology

[email protected]

http://web.mst.edu/~cetinkayae/teaching/CPE2210Spring2018

2 March 2018 rev. 18.0 © 2014–2018 Egemen K. Çetinkaya

Page 2: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Multipliers/DividersOutline

• Introduction

• Multipliers

• Dividers

• ALUs

• Summary

MST CPE2210 – Multipliers/Dividers2 March 2018 2

Page 3: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Digital Logic SystemsOverview

• Combinatorial logic circuits for no memory systems

– Boolean algebra to mathematically design/analyze

– logic gates are building blocks

• Sequential logic circuits for memory systems

– Finite State Machines to mathematically design/analyze

– flip-flops and latches store memory

• flip-flops and latches are building blocks of sequential logic

• Sequential logic circuits (aka controllers) combine

– combinatorial circuits

– storage elements (e.g. registers)

MST CPE2210 – Multipliers/Dividers2 March 2018 3

Page 4: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Digital SystemsComponents

• Transducer: sensor + actuator

• Not all sensors/actuators require A2D/D2A conversion

• Digital system can be implemented:

– microprocessor

• readily available, cheap, easy to program, easy to reprogram

– custom circuit

• smaller, faster, consume less power

2 March 2018 MST CPE2210 – Multipliers/Dividers 4

sensors andother inputs

Digital System

actuators andother outputs

A2D

D2A

analogphenomena

electricsignal

digitaldata

digitaldata

electricsignal

digitaldata

digitaldata

Page 5: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Digital SystemsPaths

• Digital systems have two paths:

– datapath circuit

– control circuit

• Datapath circuit

– store data

– manipulate data

– transfer data from one part to another

• Control circuit

– controls the operation of datapath circuit

MST CPE2210 – Multipliers/Dividers2 March 2018 5

Page 6: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Datapath ComponentsBuilding Block examples

• Adders

• Subtractors

• Comparators

• ALUs: Arithmetic Logic Units

• Registers

• Shifters

• Multiplexer/demultiplexers

• Encoders/decoders

• Counters/timers

MST CPE2210 – Multipliers/Dividers2 March 2018 6

Page 7: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

AddersHalf-Adder

• Adds two bits, generates sum bit and carry-out bit

• Lets try to design the circuit:

• Next steps?

• Implement as a circuit

co = ab, s = a b

MST CPE2210 – Multipliers/Dividers2 March 2018 7

b

co s

0

a ci

A:

B:+ 0

1 1 1 1

1

1

b

co s

1

a ci

1

1

b

co s

0

a ci

1

0

b

co s

1 SUM

a

0

a b

co s

co s

a b

Half-adder

(HA)

Page 8: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

AddersFull-Adder

• Adds three bits, generates sum bit and carry-out bit

• Lets try to design the circuit:

• Next steps?

• Implement as a circuit

• co = ab + ac + bc

• s = a b c

MST CPE2210 – Multipliers/Dividers2 March 2018 8

co

ciba

s

Full

adder

(FA)

co s

a b

Full-adder

(FA)

ci

Page 9: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

AddersCarry-Ripple Adder

• Carry-ripple adder: Uses half- and full-adders

• E.g.: 4-bit carry-ripple adder

– can build any size adder based on full- and half-adders

MST CPE2210 – Multipliers/Dividers2 March 2018 9

a3

co s

FA

co

b3 a2 b2

s3 s2 s1

ciba

co s

FA

ciba

a1 b1

co s

FA

ciba

s0

a0 b0

co s

HA

ba

a3a2a1a0 b3

s3 s2 s1 s0co

b2b1b0

4-bit adder

Page 10: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

AddersCarry-Ripple Adder

• Carry-ripple adder: Can also use only full-adders

• E.g.: 4-bit carry-ripple adder

MST CPE2210 – Multipliers/Dividers2 March 2018 10

a3

co s

FA

co

b3 a2 b2

s3 s2 s1

ciba

co s

FA

ciba

a1 b1

co s

FA

ciba

s0

a0 b0 ci

co s

FA

ciba a3a2a1a0 b3

s3 s2 s1 s0co

ci

b2b1b0

4-bit adder

Page 11: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

ComparisonHalf-Adder vs. Half-Subtractor

• HA operation: a+b

• s = a b

• co = ab

MST CPE2210 – Multipliers/Dividers2 March 2018 11

a b

co s

co s

a b

Half-adder

(HA)

• HS operation: b−a

• D = a b

• B = b’a

a b

B D

B D

a b

Half-

subtractor

Page 12: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

ComparisonFull-Adder vs. Full-Subtractor

• FA operation: a+b+c

• s = a b c

• co = ab + ac + bc

MST CPE2210 – Multipliers/Dividers2 March 2018 12

• FS operation: b−a−Bi

• D = b a Bi

• Bo = b’ (a Bi) + aBi

co

ciba

s

Full

adder

(FA)

Bo

Biba

D

(FS)

Page 13: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

SubtractorsSubtraction via 2’s Complements

• Subtraction via adding 2’s complement

• A B = A + (B)

• A B = A + (2’s complement of B)

• A B = A + (inverted B + 1)

MST CPE2210 – Multipliers/Dividers2 March 2018 13

1cin

BAAdder

S

BA

N-bit

Page 14: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• Lets shift left one

MST CPE2210 – Multipliers/Dividers2 March 2018 14

0 1 1 0 1 1 0 1

Page 15: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• Lets shift left one

• After moving one bit to left?

MST CPE2210 – Multipliers/Dividers2 March 2018 15

0 1 1 0 1 1 0 1

Page 16: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• Lets shift left one

• After moving one bit to left

• dropped the MSB added 0 for LSB

MST CPE2210 – Multipliers/Dividers2 March 2018 16

0 1 1 0 1 1 0 1

1 1 0 1 1 0 1 0

Page 17: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• Lets shift left 2-bits

• After first shift left

• After second shift left

MST CPE2210 – Multipliers/Dividers2 March 2018 17

0 1 1 0 1 1 0 1

Page 18: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• Lets shift left 2-bits

• After first shift left

• After second shift left

MST CPE2210 – Multipliers/Dividers2 March 2018 18

0 1 1 0 1 1 0 1

1 1 0 1 1 0 1 0

Page 19: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• Lets shift left 2-bits

• After first shift left

• After second shift left

MST CPE2210 – Multipliers/Dividers2 March 2018 19

0 1 1 0 1 1 0 1

1 1 0 1 1 0 1 0

1 0 1 1 0 1 0 0

Page 20: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• What was the arithmetic operation we just did?

MST CPE2210 – Multipliers/Dividers2 March 2018 20

Page 21: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Left Operation Example

• Shift left n-bits will multiply by 2n

MST CPE2210 – Multipliers/Dividers2 March 2018 21

Page 22: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• Lets shift right one

MST CPE2210 – Multipliers/Dividers2 March 2018 22

0 1 1 0 1 1 0 1

Page 23: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• Lets shift right one

• After moving one bit to right?

MST CPE2210 – Multipliers/Dividers2 March 2018 23

0 1 1 0 1 1 0 1

Page 24: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• Lets shift right one

• After moving one bit to right

• Added 0 for MSB dropped the LSB

MST CPE2210 – Multipliers/Dividers2 March 2018 24

0 1 1 0 1 1 0 1

0 0 1 1 0 1 1 0

Page 25: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• Lets shift right 2-bits

• After first shift right

• After second shift right

MST CPE2210 – Multipliers/Dividers2 March 2018 25

0 1 1 0 1 1 0 1

Page 26: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• Lets shift right 2-bits

• After first shift right

• After second shift right

MST CPE2210 – Multipliers/Dividers2 March 2018 26

0 1 1 0 1 1 0 1

0 0 1 1 0 1 1 0

Page 27: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• Lets shift right 2-bits

• After first shift right

• After second shift right

MST CPE2210 – Multipliers/Dividers2 March 2018 27

0 1 1 0 1 1 0 1

0 0 1 1 0 1 1 0

0 0 0 1 1 0 1 1

Page 28: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• What was the arithmetic operation we just did?

MST CPE2210 – Multipliers/Dividers2 March 2018 28

Page 29: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Shift RegisterShift Right Operation Example

• Shift right n-bits will divide by 2n

MST CPE2210 – Multipliers/Dividers2 March 2018 29

Page 30: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Division via ShiftSigned Number Example

• Previous examples were unsigned numbers

• Need to preserve the sign for signed numbers

• Consider A = 24 = 011000

• A/2 = 24/2 = 12 = 001100

• A/4 = 24/4 = 6 = 000110

• Consider A = −24 = 101000

• A/2 = −24/2 = −12 = 110100

• A/4 = −24/4 = −6 = 111010

MST CPE2210 – Multipliers/Dividers2 March 2018 30

Page 31: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

MultipliersMultiplication Operation

• Multiplication product via multiplicand and multiplier

MST CPE2210 – Multipliers/Dividers2 March 2018 31

1 1 1 0

1 1 1 0

1 0 1 1

1 1 1 0

0 0 0 0

1 1 1 0

1 0 0 1 1 0 1 0

Multiplicand M

Multiplier Q

Product P

(14)

(11)

(154)

Page 32: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

MultipliersMultiplication Operation

• Multiplication results in partial products

MST CPE2210 – Multipliers/Dividers2 March 2018 32

1 1 1 0

1 1 1 0

1 0 1 1

1 1 1 0

1 0 0 1 1 0 1 0

Multiplicand M

Multiplier Q

Product P

(14)

(11)

(154)

+

1 0 1 0 1

0 0 0 0+

0 1 0 1 0

1 1 1 0+

Partial product 1

Partial product 2

Partial product 3

Page 33: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Multiplier CircuitArray Style Multiplier

• Multiplication by hand can be mimicked

MST CPE2210 – Multipliers/Dividers2 March 2018 33

Page 34: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Multiplier CircuitArray Style Multiplier

• Generalized representation of multiplication by hand

MST CPE2210 – Multipliers/Dividers2 March 2018 34

Page 35: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Multiplier CircuitArray Style Multiplier

MST CPE2210 – Multipliers/Dividers2 March 2018 35

A B

Block symbol

+ (5-bit)

+ (6-bit)

+ (7-bit)

0 0

0 0 0

0

a0a1a2a3

b0

b1

b2

b3

0

p7..p0pp1

pp2

pp3

pp4

Page 36: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

DividersDivision Operation

• Dividend divided by divisor resulting in Q and R

MST CPE2210 – Multipliers/Dividers2 March 2018 36

9 1409

5045

5

15 100

1010

011001001

00001111

1001

00101

100001001

11101001

101

Quotient

DividendDivisor

Remainder

Page 37: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

• A/B produces Q and R

Divider CircuitArray Style Divider

MST CPE2210 – Multipliers/Dividers2 March 2018 37

The most significant bit of the

dividend A then becomes the

least significant bit of R. The

divisor B is repeatedly

subtracted from this partial

remainder to determine

whether it fits.

More info [HH2013] [EL2004]

Page 38: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

ALUsArithmetic Logic Units

• Arithmetic Logic Unit (ALU)

• ALUs performs Boolean and arithmetic functions

• Performs operations on n-bit operands

– e.g. 4-bit addition, subtraction

– e.g. 8-bit addition, subtraction

• Functions include on TI 74S381 ALU chip:

– Clear, A−B, A+B, XOR, OR, AND, Preset

MST CPE2210 – Multipliers/Dividers2 March 2018 38

Page 39: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

Multipliers/DividersSummary

• Many multipliers design exists

• Division is a slow and expensive operation

• Need to preserve the sign for signed numbers

– when doing multiplication/division via shifting

• ALUs performs Boolean and arithmetic functions

MST CPE2210 – Multipliers/Dividers2 March 2018 39

Page 40: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

References and Further Reading

• [V2011] Frank Vahid, Digital Design with RTL Design, VHDL, and Verilog, 2nd edition, Wiley, 2011.

• [BV2009] Stephen Brown and Zvonko Vranesic, Fundamentals of Digital Logic with VHDL Design, 3rd edition, McGraw-Hill, 2009.

• [G2003] Donald D. Givone, Digital Principles and Design, McGraw-Hill, 2003.

• [HH2013] David Harris and Sarah Harris, Digital Design and Computer Architecture, 2nd edition, Morgan Kaufmann, 2013.

• [EL2004] Miloš D. Ercegovac and Tomás Lang, Digital Arithmetic, 1st edition, Morgan Kaufmann, 2004.

MST CPE2210 – Multipliers/Dividers2 March 2018 40

Page 41: Introduction to Digital Logic - web.mst.eduweb.mst.edu/~cetinkayae/teaching/CPE2210Spring2018/... · Introduction to Digital Logic ... Egemen K. Çetinkaya Department of Electrical

© Egemen K. Çetinkaya

End of Foils

MST CPE2210 – Multipliers/Dividers2 March 2018 41