Registers and Counters
完整文本记录
so now that we have a pretty good idea
of how to build sequential devices
uh in a general description we can build
out a couple of standard sequential
devices that we will use when we build
our data path
uh this is just like in the
combinational logic section where we
built out a few
standard combinational logic devices
like multiplexers and decoders
here we're going to build registers and
then we're going to build
counters both of these are standard
devices that we will end up using
in our data path so a register is the
first one we'll build and it's a pretty
straightforward device the idea is to
store and be able to manipulate a
collection of
individual bits that are treated
together like a
word uh so a collection of bits that
represent the number
or some other piece of information and
the size of these registers is going to
dictate the
the sort of size of the data path of the
computer that we're going to build so a
32-bit computer has 32-bit chunks of
information passed around
as stored and retrieved in 32-bit
registers
a register is just a collection of these
bits so we're going to build a register
that is going to be able to store and
also
shift this is another function that
these registers often have
which allows us to move the information
on the register up or down by one bit
that has a particular functionality as
you'll see and then we'll build some
counters
we've built general purpose counters
already in our sequential design process
but we'll build a couple of
specific counters that just count
sequentially one two three four five
and you'll see that there are some
standard simplifications that we can
make in that process as well
so a register is just a collection it's
going to be a collection of d
flip flops because the d flip flop is
the flip flop that we use
when we want to just store a piece of
information we present at the input of
the flip flop
the information that we want to store
and then the design
process for a register is very
straightforward all we do
is present at the input of the d flip
flop and we use a multiplexer to
select what we're going to present at
the input of the d flip flop to store
what we want to store so we're going to
build one
slice of the register first we call this
a bit slice and this is just like when
we built the adders and subtractors
we built a slice of the device that will
handle one bit at a time
and then we expand that design to the
entire device so in this case we'll
build a single slice and this register
example that we're going to walk through
can do four different things
it can store the information it's
already there so make no change
it can shift the information left or
right and it can load new information
from the outside world
so let's have a look at what that looks
like so again we have a multiplexer
and we have a design principle that
we've used in the past
uh you know in other other programs the
multiplexer might sort of have a
different shape and we might have
the control lines out the side for
example but in the
logic works program it's just a box and
the control logic is right here
and then depending on the control inputs
one of four
possible data inputs are routed through
to the
data output of the multiplexer
and then that's just presented to the
input of our flip flop
now the four different functions that
this particular register will have
first of all we can load information in
from the outside world
that's for if the control logic is set
to three
if the control logic is set to one or
two
then we might shift and that means that
we'll bring information for this
particular slice
from the left to or sorry from the right
if we're shifting left
or from the left if we're shifting right
and we'll see how that works once we
stack the bit slices together
and then the last function is just to
store the current value
now this is something that people
sometimes get confused about because the
flip flop
generally has this storage procedure
already built in why do we need a
multiplexer to do it
well the storage process for a d flip
flop relies on the clock to be either
high or low
and we really want the clock to be
synchronized across all of these devices
we want every device in our machine to
be on the same clock
so we don't really want to modify that
clock very much we're going to have that
clock just be
its value so instead what we're going to
do is take the current value that's
stored in the flip-flop and we're going
to route it back
and present it as one input to the
multiplexer
and then if that's the function that we
choose then that value gets routed
through and presented back at the input
again
and to store then information we just
store that information around and around
and it just sort of reinforces that same
value whatever it is back again at the
input of the
d flip flop for this particular bit
slice so if we're going to
put a few of these together it looks
like this
each individual slice can take
information
in its multiplexer inputs from the
current value
for d0 it can take information from
the slice to the right if we're going to
be shifting to the left
it can take information from the slice
to the left if it's going to be shifting
to the right
and it can take information from the
outside world
in a load so those are the four
different things that each bit slice can
do
and you can see that if you ask this
register to shift a value one bit to the
right
then each um each
flip-flop will take a value from the
multiplexer that is routed
from the previous flip-flop and they
will just go one to the next oops that's
not right
one to the next one to the next and the
whole value will just be shifted one bit
to the right and the same for the left
if you're
going the other direction it will shift
one bit to the left now when we shift to
the right
we have to make a decision as to what to
do to this top bit
because there's no value to shift in so
we have to have an
input from the outside world that we'll
bring in and usually we just shift a
zero
in because it's simpler and the same
thing for the left if we're shifting
from
the shifting to the left we have to
evaluate the lower bit
to shift some value in uh this does
bring up the question of what actually