CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple...
Transcript of CS64 Lecture15 SequentialLogic · Sequential Logic • Combinatorial Logic – Combining multiple...
![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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/1.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/3.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/4.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/5.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/6.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/7.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/8.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/9.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/10.jpg)
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
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/11.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/12.jpg)
ClockedDLatchasSampler
• Thisclockedlatchcanbeusedasa“programmable”memorydevicethat“samples”aninputonaregularbasis
3/8/18 Matni,CS64,Wi18 12
DCLK
![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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/13.jpg)
TheClockedLatchByAnyOtherName…
• Observinginputandoutput“waveforms”
3/8/18 Matni,CS64,Wi18 13
DCLK
SR
DClockedLatch
DCLK
![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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/14.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/15.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/16.jpg)
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
DGatedLatch
DCLK
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/17.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/18.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/19.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/20.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/21.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/22.jpg)
HintsforTask2
3/8/18 Matni,CS64,Wi18 22
01S
01S
O1O2
GatedDLatch
DE
GatedDLatch
DE
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/23.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/24.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/25.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/26.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/27.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022063003/5f6b830abb476a012956170c/html5/thumbnails/28.jpg)
3/8/18 Matni,CS64,Wi18 28