module top_module( input clk,
input load,
input [255:0] data,
output [255:0] q );
reg [3:0] c;
integer i;
always @(posedge clk)begin
if(load)begin
q <= data;
end
else begin
for(i=0;i<255;i++)begin
if (i==0)begin
c=q[1]+q[31]+q[16]+q[255]+q[17]+q[15]+q[240]+q[241];
end
else if (i>0&&i<15)begin
c=q[i+16]+q[i+17]+q[i-1]+q[i+1]+q[i+15]+q[239+i]+q[240+i]+q[241+i];
end
else if(i==255)begin
c =q[254] + q[255] + q[240] + q[14] + q[0] + q[30] + q[31] + q[16];
end
else if (i==240)begin
c=q[1]+q[225]+q[226]+q[239]+q[255]+q[15]+q[0]+q[241];
end
else if(i == 15)begin
c =q[254] + q[255] + q[240] + q[14] + q[0] + q[30] + q[31] + q[16];
end
else if(i>240 && i<255)begin
c =q[i-17]+q[i-16]+q[i-15]+q[i-1]+q[i+1]+q[i-239]+q[i-240]+q[i-241];
end
else if(i%16==0)begin
c =q[i+17]+q[i-16]+q[i-1]+q[i-15]+q[i+15]+q[i+1]+q[i+31]+q[i+16];
end
else if(i%16==15)begin
c =q[i-17]+q[i-16]+q[i-31]+q[i-1]+q[i-15]+q[i+15]+q[i+16]+q[i+1];
end
else begin
c =q[i-17]+q[i-16]+q[i-15]+q[i-1]+q[i+1]+q[i+15]+q[i+16]+q[i+17];
end
case(c)
4'b0010:q[i] <= q[i];
4'b0011:q[i] <= 1'b1;
default:q[i] <= 1'b0;
endcase
end
end
end
endmodule
顺序有问题,改一下就正确了