Registers and Counters

Uses | Loading | Counters


The Need for Registers

A long series of flip-flops

It is quite easy to build constants into a digital circuit. All that must be done is to use a high voltage (typically 5V DC) for logic value "true" and use a wire connected to ground (0V DC) for logic value "false." When variables are needed, it is a very different matter. Certainly, switches can be used, but switches usually need someone to throw them. The solution? Registers.

Registers are used to hold variable numbers that need to be gotten at quickly and that often change. A register is principally made of either many flip-flops, or a small dedicated portion of very fast memory. The distinction is not important to CMSC 311, since both work largely the same way to circuits that use them. When building circuits involving variables, flip-flops are not quite as simple as RAM. RAM is alomost always treated as something that gives back an answer a specified amount of time after being asked, and further discussion is beyond the scope of this course. Flip-flops, on the other hand, are easier to grasp in their internal mechanics, and therefore a detailed discussion of how they work is possible. (If you don't remember exactly how a flip-flop works, read the flip-flop page again.)

It is important to state that all registers can be treated as being composed of flip-flops. On this page, we shall deal with specific types of registers that alter their contents, but registers exist that only store data.


Parallel Load

A typical register is at least 32 bits long. That means that we will need 32 flip-flops to build it. Setting each flip-flip sequentially is not a useful idea, since we can set them all at once quite easily. Just make sure that the proper input value is set on the input wires, and send a clock pulse. For simplicity's sake, we will use flip-flops with only one input, a clock signal, a clear signal, and a single output line (even though all flip-flips have both complemented and uncomplemented output).

In the diagram that starts above and to the right, the flip-flops all have independent inputs, but the same clock and the same reset. (The reset actually isn't very important, but sometimes it's nice to be able to clear something easily. A shared reset is easier than ensuring that all inputs are 0 and sending a clock pulse.) The "..." represents the 26 flip-flips corresponding to bits 5 through 30, which look just like the 6 that are shown. The unmarked wires are inputs, which can be anything that need to be stored.

The technique of storing all the data at once is called "parallel load." It isn't extremely complicated, but it is an important concept to be able to recognize.


Counters

a shift register, using D flip-flops

Another important type of circuit involving registers performs counting. There are two varieties important to CMSC 311: shift counters, also known as shift registers, and ripple counters, also known as incrementers (or decrementers). Shift counters are easier to create than incrementers, and a circuit composed of serial D flip-flops that implements a shift register starts above and to the left.

A shift register is a vital component in most ALUs. It takes data and shifts the bits in a predetermined direction. This is handy for multiplying and dividing by 2 (shift left once = multiply by 2, shift right once = divide by 2), and provides a useful hardware interface for shifting data bits.

As an example, if we load the shift register with the 8 bit sequence 10011011 (and then short In 0 to ground so that it gets only 0s thereafter), the circuit will contain 10011011 (with the most significant bit at the bottom and the least significant bit at the top) at time 0. At time 1, it will contain 00110110. This sequence will be followed by 01101100, 11011000, 10110000, 01100000, 11000000, 10000000, and will remain 00000000 until a new sequence is loaded. Notice that the value seems to ripple to the left; hence the name.

Note that it is quite simple to convert the 4 bit shift register shown to an 8 bit shift register, or longer, just by adding more D flip-flops in series. It is important to realize that not all shift registers allow access to each bit at any given time; often, just the most significant bit is available at any time. [The short reason is because shift registers are also used in synchronous circuits like sequence detectors that only take bits serially, not in parallel. For more detail, ask an electrical engineering student.]

It is left as an exercise to perform the following tasks on the shift register circuit shown.


an incrementer, using D flip-flops
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
An incrementer is a similar circuit, which takes a number in binary form and increments it, once per clock tick. Note that this is not a half or full adder - those add any two numbers together in finite time, while this increments a number by one each clock tick. This circuit is useful for loop control and simple increments and decrements.

One implementation, using negative-edge triggered flip-flops, is at the right. Note that it is simple to extend this to an 8 bit (or any finite number) incrementer by increasing the number of D flip-flops.

Notice that this circuit uses an interesting method to run the flip-flops. Since this circuit uses negative-edge triggered flip-flips, flip-flops only change state when the flip-flop above it goes from 1 to 0. If we look at a list of the first 15 numbers to the left, we see that this is the appropriate course of action to take. A column only toggles at the moment when the column to the right changes from 1 to 0. (Actually, there is a small time delay between neighbors changing state, but this is negligible compared to the amount of time that the flip-flop stays in the same state.)

It is left as an exercise to perform the following alterations to the incrementer circuit shown.



Back to the Table of Contents.