A upcounter described as such will continue to count whenever the flipflops are driven

by the clock.

Say we wanted to turn the counter off and on?

The first bit, Q0, is fed by the equation D0. Its change is dependent on the second input to the xor gate, which we see is hardwired to a one. If we xor a zero, there is no change to the least significant digit, and the counter won't count.

The LFSR is built on the idea of a shift register. This is constructed by taking the output of a DFF and connecting it directly to the input on a second DFF. Lets consider the case of a n bit shift register.

Data placed on D is shifted into the DFFs modeled by the always@ process & the reg data type. The data available on the output is the nth data bit, so over time data would be shifted in and made available. Table 1 below shows the operation of the shift register.

"The only linear functions of single bits are xor and inverse-xor; thus it is a shift register whose input bit is driven by the exclusive-or (xor) of some bits of the overall shift register value.

The initial value of the LFSR is called the seed, and because the operation of the register is deterministic, the stream of values produced by the register is completely determined by its current (or previous) state. Likewise, because the register has a finite number of possible states, it must eventually enter a repeating cycle. However, an LFSR with a well-chosen feedback function can produce a sequence of bits which appears random and which has a very long cycle.

Fibonacci LSFRs
The bits in the LFSR state which influence the input are called taps.
A maximum-length LFSR produces an m-sequence (i.e. it cycles through all possible 2n − 1 states within the shift register except the state where all bits are zero), unless it contains all zeros, in which case it will never change.
As an alternative to the XOR based feedback in a standard LFSR, one can also use XNOR. A state with all ones is illegal when using an XNOR feedback, in the same way as a state with all zeroes is illegal when using XOR. This state is considered illegal because the counter would remain "locked-up" in this state.

End Wikipedia

Maximal length LFSRs are built with specially choosen taps, which are represented by polynomials. The 3 bit LFSR polynomial
x^3+x^2+1 could be represented by the following implementation.

Code 2 shows the implementation taking place inside the always@ block. There are different ways to do this, this is just one example. For homework/exercise, implement a LFSR with a maximal length polynomial. Use a 4, 5, 6, 7 or 8 bit polynomial from the Wikipedia LFSR page in your implementation and build a testbench to simulate it.

Awesomeness points are awarded for a selfchecking testbench which actually proves that the LFSR is maximal length.