你写的程序就不大好懂,我觉的要这样写就好了:
module johnsoncounter(clk,pre,q);
parameter NBITS=8;
input clk,pre;
output [NBITS:1] q;
reg [NBITS:1] q;
always @(negedge pre or negedge clk)
if(!pre)
q<=0;
else
begin
if(!q[NBITS])
q<={q[NBITS-1:1],1'b1};
else
q<={q[NBITS-1:1],1'b0};
end
endmodule
module TB_tb;
parameter N=8;
reg Clk,Pre;
wire [N:1] Q;
johnsoncounter UUt(.clk(Clk),.pre(Pre),.q(Q));
initial
begin
Pre=1'b0;
Clk=1'b0;
#20 Pre=1'b1;
forever #10 Clk=~Clk;
end
endmodule