next up previous contents
Next: E ABEL Source Code Up: D C Source Code Previous: D.6 capture.c

D.7 lfsr.c

 

/* lfsr.c
** Scott Harrington
** Program to print out the sequence produced by the 15-bit
** linear feedback shift register used as a fifo counter.
*/

#include <stdio.h>
#include <stdlib.h>

#define BIT(n,x) ( ( (x) >> (n) ) & 1 )

void main()
    {
    unsigned reg;
    int feedback;

    reg = 0;
    do {
        printf("%u\n", reg);
        feedback = (BIT(14,reg) == BIT(13,reg));    /* reg[14] XNOR reg[13] */
        reg = (reg<<1) + feedback;
        reg &= 0x7FFF;
        }
    while (reg != 0);
    }


Scott E. Harrington
Sat Apr 29 18:56:25 EDT 1995