integer tag = 0; always @(posedge clk) begin case(tag) 0:begin line=4'b0001; tag = 1; end 1:begin line=4'b0010; tag = 2; end 2:begin line=4'b0100; tag = 3; end 3:begin line=4'b1000; tag = 0; end endcase end endmodule
module test ( input clk, input[2:0] a, input[2:0] b,
output reg a_light, output reg b_light );
integer tag = 0; integer G ; always @(posedge clk) begin case(tag) 0:begin G=10; tag = 1; a_light=0; b_light=0; end 1:begin//比较 if(a>b)begin tag = 2; end else if(a<b) begin tag = 3; end else begin tag = 4; end end 2:begin//a赢 G = G + 1; tag = 5; end 3:begin//b赢 G = G - 1; tag = 6; end 4:begin//平 if(G>10)begin G = G - 1; end else if(G<10) begin G = G + 1; end tag = 9; end 5:begin if(G >= 20)begin tag = 7; end else begin tag = 1; end end 6:begin if(G <= 0)begin tag = 8; end else begin tag = 1; end end 7:begin//亮a灯 a_light=1; b_light=0; tag = 0; end 8:begin//亮b灯 a_light=0; b_light=1; tag = 0; end 9:begin//亮ab灯 a_light=1; b_light=1; tag = 1 ; end endcase end endmodule