latches, flip-flops, and registers - wellesley collegecs240/s16/slides/registers.pdf · can be done...
TRANSCRIPT
![Page 1: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/1.jpg)
Latches,Flip-flops,andRegisters
Sequential logic:fundamental elements tostorevaluesOutputdependsoninputsandstoredvalues.
(vs. combinational logic:outputdependsonlyoninputs)
Latch:CC-BYRberteig@flickr
![Page 2: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/2.jpg)
ALU
Processor:DataPathComponents
Registers MemoryInstructionFetch andDecode
12
![Page 3: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/3.jpg)
Bistable latches
Q Q
Supposewesomehowgeta1(ora0?)onhere.
Q Q00=
![Page 4: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/4.jpg)
SRlatch
Q QRS
Set Reset
S R Q Q' Q(stable) Q' (stable)0 0 0 0 ? ?0 0 0 1 0 10 0 1 0 1 00 0 1 1 ? ?1 0 ? ? 1 00 1 ? ? 0 1
![Page 5: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/5.jpg)
SRlatch
Q QRS
R
S
Q
QR
S R
S Q
Q
R
S Q
Q
![Page 6: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/6.jpg)
ifC=0,thenSRlatchstorescurrentvalueofQ.ifC=1,thenDflowstoQ:
ifD=0,thenR=1andS=0,Q=0ifD=1,thenR=0andS=1,Q=1
Dlatch
D
C
R
S
Q
Q
Clock
Databit
![Page 7: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/7.jpg)
ClocksClock:free-running signalwithfixedcycle time=clockperiod =T.Clockfrequency =1/clockperiod
Aclockcontrolswhentoupdateasequential logicelement's state.
Clockperiod
Fallingedge
Risingedge
![Page 8: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/8.jpg)
Synchronous systemsInputstostateelementsmustbevalid onactiveclockedge.
Stateelement
1
Stateelement
2Combinational logic
![Page 9: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/9.jpg)
Dflip-flopwithfalling-edgetrigger
D
C
QEQmDm
CmDlatch
Qm
QsDs
CsDlatch
Qs Q
leader follower
ClockleaderstoresD asE
folower storesE asQ
CanstillreadQnow Qnext becomesQnow
Time
![Page 10: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/10.jpg)
Readingandwriting inthesamecycle
ClockleaderstoresD asE
followerstoresE asQ
Time
CanwriteQnextwhilesimultaneouslyreadingstateQnow
CanstillreadQnow Qnext becomesQnow
QD
CD Flip-Flop
QClock
![Page 11: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/11.jpg)
Dflip-flop=onebitofstorage
QD
CD Flip-Flop
Q
1
![Page 12: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/12.jpg)
A1-nybble*register(a4-bithardwarestoragecell)
Write
Clock
0
1
0
1
QD
CD Flip-Flop
QQD
CD Flip-Flop
QQD
CD Flip-Flop
QQD
CD Flip-Flop
Q
*Halfabyte!
![Page 13: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/13.jpg)
Registerfile
ReadportsWhy2?
Readregisterselector1Readregisterselector2
WriteregisterselectorWritedata
Write?
Readdata1
Readdata2
r
r
r
w
w
w
r=log2 numberofregistersw=bitsinword
Arrayofregisters,withregisterselectors,write/readcontrol,inputportforwritingdata,outputportsforreadingdata.
Writeport0=read1=write
![Page 14: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/14.jpg)
Readports(dataout)
C.8 Memory Elements: Flip-Flops, Latches, and Registers C-55
FIGURE C.8.7 A register fi le with two read ports and one write port has fi ve inputs and two outputs. The control input Write is shown in color.
FIGURE C.8.8 The implementation of two read ports for a register fi le with n registers can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number sig nal is used as the multiplexor selector signal. Figure C.8.9 shows how the write port is implemented.
Read registernumber 1 Read
data 1Read registernumber 2
Read data 2
Writeregister
WriteWritedata
Register file
Read registernumber 1
Register 0
Register 1
. . .
Register n – 2
Register n – 1
M
u
x
Read registernumber 2
M
u
x
Read data 1
Read data 2
AppendixC-9780123747501.indd 55AppendixC-9780123747501.indd 55 26/07/11 6:29 PM26/07/11 6:29 PM
![Page 15: Latches, Flip-flops, and Registers - Wellesley Collegecs240/s16/slides/registers.pdf · can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number](https://reader031.vdocument.in/reader031/viewer/2022040408/5eb97d881304c309bc0d0c71/html5/thumbnails/15.jpg)
FIGURE C.8.9 The write port for a register fi le is implemented with a decoder that is used with the write signal to generate the C input to the registers. All three inputs (the regis ter number, the data, and the write signal) will have setup and hold-time constraints that ensure that the correct data is written into the register fi le.
Write
01
n-to-2n
decoder
n – 2
n – 1
Register 0
C
D
Register 1
C
D
Register n – 2
C
D
Register n – 1
C
D
...
Register number...
Register data
valid during the time it is read, as we saw earlier in Figure C.7.2. The value returned will be the value written in an earlier clock cycle. If we want a read to return the value currently being written, additional logic in the register fi le or out side of it is needed. Chapter 4 makes extensive use of such logic.
Specifying Sequential Logic in VerilogTo specify sequential logic in Verilog, we must understand how to generate a clock, how to describe when a value is written into a register, and how to specify sequential control. Let us start by specifying a clock. A clock is not a predefi ned object in Verilog; instead, we generate a clock by using the Verilog notation #n before a statement; this causes a delay of n simulation time steps before the execu tion of the statement. In most Verilog simulators, it is also possible to generate a clock as an external input, allowing the user to specify at simulation time the number of clock cycles during which to run a simulation.
The code in Figure C.8.10 implements a simple clock that is high or low for one simulation unit and then switches state. We use the delay capability and blocking assignment to implement the clock.
C-56 Appendix C The Basics of Logic Design
AppendixC-9780123747501.indd 56AppendixC-9780123747501.indd 56 26/07/11 6:29 PM26/07/11 6:29 PM
Writeport (datain)
incomingdata
registernumber
writecontrolclock