28
Sequential Logic CS 64: Computer Organization and Design Logic Lecture #15 Ziad Matni Dept. of Computer Science, UCSB

CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

SequentialLogic

CS64:ComputerOrganizationandDesignLogicLecture#15

ZiadMatni

Dept.ofComputerScience,UCSB

Page 2: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

LectureOutline

•  SequentialLogic

•  S-RLatch

•  D-Latch

•  D-FlipFlop

•  Reviewingwhat’sneededforLab8

3/8/18 Matni,CS64,Wi18 2

Page 3: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

AbstractSchematicoftheMIPSCPU

3/8/18 Matni,CS64,Wi18 3

Page 4: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

SequentialLogic

•  CombinatorialLogic–  Combiningmultiplelogicblocks–  Theoutputisafunctiononlyofthepresentinputs–  Thereisnomemoryofpast“states”

•  SequentialLogic–  Combiningmultiplelogicblocks–  Theoutputisafunctionofbothpresentandpastinputs–  Thereexistsamemoryofpast“states”

3/8/18 Matni,CS64,Wi18 4

Page 5: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TheS-RLatch

•  Onlyinvolves2NORs

•  Theoutputsarefed-backtotheinputs

•  Theresultisthattheoutputstate(eithera1ora0)ismaintainedeveniftheinputchanges!

3/8/18 Matni,CS64,Wi18 5

Page 6: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

HowaLatchWorks•  NotethatifoneNORinputis0,theoutput

becomestheinverseoftheotherinput

•  So,ifoutputQalreadyexistsandifS=0,R=0,thenQwillremainatwhateveritwasbefore!(holdoutputstate)

•  IfS=0,R=1,thenQbecomes0(resetoutput)

•  IfS=1,R=0,thenQbecomes1(setoutput)

•  MakingS=1,R=1isnotallowed(undeterminedoutput)3/8/18 6

S R Q0 Comment0 0 Q* Holdoutput0 1 0 Resetoutput1 0 1 Setoutput1 1 X Undetermined

Page 7: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

Consequences?

•  AslongasS=0andR=0,thecircuitoutputholdsmemoryofitspriorvalue(state)

•  Tochangetheoutput,justmakeS=1(butalsoR=0)tomaketheoutput1(set)ORS=0(butalsoR=1)tomaketheoutput0(reset)

•  JustavoidS=1,R=1…

3/8/18 Matni,CS64,Wi18 7

S R Q0 Comment0 0 Q* Holdoutput0 1 0 Resetoutput1 0 1 Setoutput1 1 X Undetermined

Page 8: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

AboutthatS=1,R=1Case…

•  WhatifweavoideditonpurposebymakingR=NOT(S)?– Where’stheproblem?

•  This,byitself,precludesacasewhenR=S=0–  You’dneedthatifyouwantto

preservethepreviousoutputstate!

•  Solution:theclockedlatchandtheflip-flop

3/8/18 Matni,CS64,Wi18 8

S/R’

S R Q0 Comment

0 0 Q* Holdoutput

0 1 0 Resetoutput

1 0 1 Setoutput

1 1 X Undetermined

Page 9: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

Addingan“Enable”Input:TheGatedSRLatch

•  Createawayto“gate”theDinput–  Dinputgoesthroughonlyifan

“enableinput”(E)is1–  IfEis0,thenholdthestateofthe

previousoutputs

•  So,thetruthtablewouldlooklike:

3/8/18 Matni,CS64,Wi18 9

S R Q0 Comment0 0 Q* Holdoutput0 1 0 Resetoutput1 0 1 Setoutput1 1 X Undetermined

S R E Q0 CommentX X 0 Q* Holdoutput0 1 1 0 Resetoutput1 0 1 1 Setoutput

Page 10: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TheGatedDLatch•  ForceSandRinputs

toalwaysbeoppositeofeachother–  Makethemthesameas

aninputD,whereD=Rand!D=S.

•  Createawayto“gate”theDinput–  Dinputgoesthrough

onlyifanenableinput(E)is1–  IfEis0,thenholdthestateofthe

previousoutputs

3/8/18 Matni,CS64,Wi18 10

DE

SR

QQ

D E Q0 CommentX 0 Q* Holdoutput0 1 0 Resetoutput1 1 1 Setoutput

Page 11: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TheClockedDLatch•  Ifyouapplyaclockon

inputE,yougetaclockedDlatch.

•  Aclockisaninputthatgoes1then0,then1againinasettimeperiod

•  WhenCLKis0,bothSandRinputstothelatchare0too,sotheQholdsitsvalue(Q=Q0)

3/8/18 Matni,CS64,Wi18 11

DCLK

SR

•  WhenCLKis1,thenifD=1,thenQ=1,butifD=0,thenQ=0

Page 12: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

ClockedDLatchasSampler

•  Thisclockedlatchcanbeusedasa“programmable”memorydevicethat“samples”aninputonaregularbasis

3/8/18 Matni,CS64,Wi18 12

DCLK

QQ

Page 13: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TheClockedLatchByAnyOtherName…

•  Observinginputandoutput“waveforms”

3/8/18 Matni,CS64,Wi18 13

DCLK

SR

DClockedLatch

DCLK

QQ

Page 14: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TheJoysofSampling…

•  Samplingdatainaperiodicwayisadvantageous–  Icanstartdesigningmorecomplexcircuitsthatcanhelpmedosynchronouslogicalfunctions•  Synchronous:in-time

•  VeryusefulinpipeliningdesignsusedinCPUs–  Pipelining:atechniquethatallowsCPUstoexecuteinstructionsmoreefficiently–inparallel

3/8/18 Matni,CS64,Wi18 14

Instructionfetch,decode,execute,memoryaccess,registerwrite

Page 15: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TheMostEfficientWaytoSampleInputs

•  Insteadofsamplingtheinputtothelatchusingaleveloftheclock…– Thatis,whentheclockis“1”(or“0”)

•  …sampletheinputattheedgeoftheclock– Thatis,whentheclockistransitioningfrom0à1,calledarisingorpositiveedge(oritcouldbedonefrom1à0, thefallingedgea.k.anegativeedge)

3/8/18 Matni,CS64,Wi18 15

Page 16: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

AnImprovementontheLatch:TheDFlip-Flop

Don’tworryaboutthecircuitimplementationdetails,butunderstandtheuse!TheDFlip-Floponlychangestheoutput(Q)intotheinput(D)atthepositiveedge(the0à1transition)oftheclock

3/8/18 Matni,CS64,Wi18 16

DFlip-Flop(D-FF)

D>CLK

QQ

DGatedLatch

DCLK

QQ

Asopposedto:

Notethe(slight)differenceinthe2symbols…

Page 17: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TheD-FF

•  Whentheinputclockedgeisrising,theinput(D)iscapturedandplacedontheoutput(Q)–  Risingedgea.k.apositiveedgeFF–  SomeFFarenegativeedgeFF(captureonthefallingedge)

3/8/18 Matni,CS64,Wi18 17

Page 18: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

Latchesvs.FFs•  Latchescapturedataonanentire1or0oftheclock•  FFscapturedataontheedgeoftheclock

–  Thisexampleshowsthepositive(0à1)edgeused

Latchout

FFout

3/8/18 Matni,CS64,Wi18 18

FFsgiveoutless“glitchy”outputs

Page 19: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

PopularUsesforD-FFs

•  Counter

•  Serial-to-Parallelconverter

•  Digitaldelayline

3/8/18 Matni,CS64,Wi18 19

Again,don’tworryaboutthecircuitimplementationdetails,butunderstandtheuses!

Page 20: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

Lab8

3/8/18 Matni,CS64,Wi18 20

Page 21: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

RegisterObjectforLab8

3/8/18 Matni,CS64,Wi18 21

I/OName I/ODescription

R0Thefirstregistertoread,asasinglebit.If0,thenreg0shouldberead.If1,thenreg1shouldberead.

R1Thesecondregistertoread,asasinglebit.If0,thenreg0shouldberead.If1,thenreg1shouldberead.

WR

“WriteRegister”.Specifieswhichregistertowriteto.If0,thenreg0shouldbewrittento.If1,thenreg1shouldbewrittento.

WThedatathatshouldbewrittentotheregisterspecifiedbyWR.Thisisasinglebit.

WE

“WriteEnable”.If1,thenwewillwritetoaregister.If0,thenwewillnotwritetoaregister.NotethatifWE=0,thentheinputstoWRandWareeffectivelyignored.

O1

Valueofthefirstregisterread.Asdescribedpreviously,thisdependsonwhichregisterwasselectedtoberead,viaR0.

O2

Valueofthesecondregisterread.Asdescribedpreviously,thisdependsonwhichregisterwasselectedtoberead,viaR1.

Page 22: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

HintsforTask2

3/8/18 Matni,CS64,Wi18 22

01S

01S

O1O2

GatedDLatch

DE

QQ

GatedDLatch

DE

QQ

LogicGates

Page 23: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

MemoryInterfaceObjectforLab8

3/8/18 Matni,CS64,Wi18 23

I/OName I/ODescription

A0 Bit0oftheaddress(LSB)

A1 Bit1oftheaddress(MSB)

OE

“OutputEnable”.If1,thenthevalueattheaddressspecifiedbyA0andA1willberead,andsenttotheoutputlineO.If0,thenthememorywillnotbeaccessed,andthevaluesenttotheoutputlineisunspecified(couldbeeither0or1,inanunpredictablefashion).

W Thevaluetowritetomemory.

WE

“WriteEnable”.If1,thenthevaluesentintoWwillbewrittentomemoryattheaddressspecifiedbyA0andA1.If0,thennomemorywriteoccurs(thevaluesenttoWwillbeignored).

O Thevaluereadfrommemory(orunspecifiedifOE=0).

Page 24: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

Task3:BuildaMock-CPU!

3/8/18 Matni,CS64,Wi18 24

Actually, just a small instruction decoder and executor…

OP1 OP0 B0 B1 B2 Human-readableEncoding Description

0 0 0 0 0 xorreg0,reg0,reg0 ComputetheXORofthecontentsofreg0withthecontentsofreg0,storingtheresultinreg0.

0 1 1 0 1 norreg1,reg0,reg1 ComputetheNORofthecontentsofreg0withthecontentsofreg1,storingtheresultinreg1.

1 0 1 0 1 loadreg1,01 Copythebitstoredataddress01(decimal1)intoregisterreg1.

1 1 0 1 0 storereg0,10 Storethecontentsofreg0ataddress10(decimal2)1 1 1 1 1 storereg1,11 Storethecontentsofreg1ataddress11(decimal3)

ThesesaysomethingaboutwhichoperationisbeingdoneThesesaysomethingaboutwhichregistersareused

Page 25: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

HintsforTask3•  Designthefinalcircuitinpieces:

–  Onepieceforeachofthe3typesofinstruction:load,store,XOR/NOR

•  Forexample,thestoretask:–  Ifanoutputisn’tused,tieittoapermanent“0”(i.e.ground)–  Ifaninputisn’tused,thenyoucanuse“X”(don’tcare)onit

3/8/18 Matni,CS64,Wi18 25

WhatregistersamIusing?Whichinstructionbitsgowhere?

WhatcontrolsshouldIuse?Whatvaluesshouldtheybe?

HowdoIbestconnecttheregisterstothememoryinterface?Again,askyourselfifsomeoftheinputshereshouldbeop-codebits.

Istheoutputevenusedinthis“store”task?

Page 26: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

TyingInAllThePieces(Task3)

•  Nowseehowtheycanallfittogether–  Youwillhave1registerblock+1memoryinterface–  Youwon’tneedtouseanyadditionallatcheshere–  Youwillneedtousemuxesandregularlogic(andthesimpleALUyoudesignedearlier–seelabinstructionsformoredetails)

3/8/18 Matni,CS64,Wi18 26

Page 27: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

YourToDos

•  Lab#7isdueendofdayFriday

•  Lab#8isdueNEXTweekFriday

3/8/18 Matni,CS64,Wi18 27

Page 28: CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple logic blocks – The output is a function only of the present inputs – There is

3/8/18 Matni,CS64,Wi18 28