Upload
others
View
16
Download
0
Embed Size (px)
Citation preview
Latches,Flip-flops,andRegisters
Sequentiallogic:fundamentalelementstostorevaluesOutputdependsoninputsandstoredvalues.
(vs.combinationallogic:outputdependsonlyoninputs)
Latch:CC-BYRberteig@flickr
ALU
Processor:DataPathComponents
Registers MemoryInstructionFetch andDecode
12
Bistable latches
Q Q
Supposewesomehowgeta1(ora0?)onhere.
Q Q00=
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
SRlatch
Q QRS
R
S
Q
QR
S R
S Q
Q
R
S Q
Q
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
Timematters!
D
C
Q
ClocksClock:free-runningsignalwithfixedcycle time=clockperiod =T.Clockfrequency =1/clockperiod
Aclockcontrolswhentoupdateasequentiallogicelement'sstate.
Clockperiod
Fallingedge
Risingedge
SynchronoussystemsInputstostateelementsmustbevalid onactiveclockedge.
Stateelement
1
Stateelement
2Combinationallogic
Dflip-flopwithfalling-edgetrigger
D
C
QEQLDL
CLDlatch
QL
QFDF
CFDlatch
QF Q
leader follower
ClockleaderstoresD asE
folower storesE asQ
CanstillreadQnow Qnext becomesQnow
Time
Timematters!
D
C
E
Q
Readingandwritinginthesamecycle
AssumeQisinitially0.QD
CD Flip-Flop
QClock
Dflip-flop=onebitofstorage
QD
CD Flip-Flop
Q
1
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!
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
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
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
RAM(RandomAccessMemory)
Similartoregisterfile,except…
A B
16x4RAM
4to16decoder
dataout
1101
20
4-bitaddress