1

I am trying to implement a linear feedback shift register with parameterized width and coefficients:

// ...
    parameter width = 16;
    parameter [width-1:0] coeff = 16'b1110101100110110;
// ...

Is there a way to assign the XOR-chain to the input flipflop, i.e. what is a sensible way of implementing something like

assign input_wire = (coeff[0] & flops[0]) xor ... xor (coeff[width-1] & flops[width-1]);

The obvious but illegal way would be using a for-loop. Is there a way to do this outside an always-block?

Thanks

Jersey
  • 423
  • 4
  • 13
  • You can take a look at this question : http://stackoverflow.com/questions/17159397/verilog-adding-individual-bits-of-a-register-combinational-logic-register-wid which offers a solution to your problem. A way to do it in 'one line' would be to implement a parametrized module that performs the calculations – Krouitch Jan 30 '17 at 13:27

1 Answers1

0

Bitwise AND and the unary XOR-operator do the trick:

assign input_wire = ^(coefficients[width-1:0] & flops[width-1:0]);

The bitwise AND does the weighting of the flipflop outputs.

Jersey
  • 423
  • 4
  • 13