CRC32 代码不起作用

CRC32 code does not work

我刚开始使用 CRC32.So 时,我想检查我编写的代码,但我得到了 xxxxxx,因为 output.I 我不确定代码是否正确

module last_time(input [127:0]finalinput,output  [31:0]crcout1
    ,input clk);


wire [31:0]poly;
assign poly=32'h04c11db7;
reg [7:0]lsb;
reg [3:0]i;
reg [7:0]ans;
reg [31:0]nextcrc;
reg [31:0]newcrc;
reg [31:0]crcout;
reg [7:0] lut [255:0];

always@(posedge clk)
begin
 crcout=32'hffffffff;
 lsb=finalinput;

 for(i=0;i<16;i=i+1)
   begin
     ans=(8'hff^(lsb)); 
     newcrc = lut[ans];
     $readmemh("table.txt",lut); // to fill lut
     nextcrc=(newcrc)^(crcout>>8);
     lsb=lsb>>8;
   end
end

assign crcout1=nextcrc^32'hffffffff;  
endmodule

问题出在 LUT 的输入上,它应该是一个整数而不是一个 reg 值。 LUT 大小不正确

module bit32(input [31:0]msg,input [31:0]crcinitial,output reg[31:0]tableout,output [23:0]crcshifted,
output[31:0]newcrc,output reg [7:0]xor1);
wire [7:0]msglsb;

assign msglsb=msg;
wire [7:0]crclsb;
assign crclsb=crcinitial;
integer k;
reg [31:0]lut[0:255];

initial
begin
 assign xor1=(crclsb^msglsb)&8'hff;
 assign k=xor1;
 assign tableout=lut[xor1];
 $readmemh("table.txt",lut); 
end

assign crcshifted=crcinitial>>8;
assign newcrc=(tableout^crcshifted)^32'hffffffff;
endmodule