I have a Verilog program to implement an 8-bit PISO register:
module PISO(input clk ,input [7:0] par_in, output reg out_bit); reg [7:0] mem = 8'b00000000; reg [2:0] count = 3'b000; always @ (posedge clk) begin if (count == 3'b000) begin mem <= par_in; count <= 3'b111; end else begin out_bit <= mem[0]; mem <= mem >> 1; count <= count - 1; end end endmodule the problem is all outputs through the output register out_bit work fine, but the MSB, read at the very end after 7 right shifts (7 clock cycles) is read as 0, no matter the value.
For example, if the input given is 10101010, the outputs are:
Bit_out:0 Bit_out:1 Bit_out:0 Bit_out:1 Bit_out:0 Bit_out:1 Bit_out:0 Bit_out:0 //Incorrectly read MSB I have tried all manner of fixes such as changing all non blocking assignments to blocking assignments, and ensured all registers are correctly initialised, but the problem persists.
I am using iverilog version 11. How do i fix the problem with the MSB? Is it dependent on the Verilog compiler being used?