代码如下
module top_module(
input clk,
input areset, // Freshly brainwashed Lemmings walk left.
input bump_left,
input bump_right,
input ground,
input dig,
output walk_left,
output walk_right,
output aaah,
output digging );
parameter left=0,right=1,left_ground=2,right_ground=3,left_dig=4,right_dig=5;
reg [3:0]state,next_state;
always@(*)
begin
case(state)
left:if(ground)
if(dig)
next_state<=left_dig;
else
next_state<=bump_left?right:left;
else
next_state<=left_ground;
right:if(ground)
if(dig)
next_state<=right_dig;
else
next_state<=bump_right?left:right;
else
next_state<=right_ground;
left_ground:if(ground)
next_state<=left;
else
next_state<=left_ground;
right_ground:if(ground)
next_state<=right;
else
next_state<=right_ground;
left_dig:if(ground)
next_state<=left_dig;
else
next_state<=left_ground;
right_dig:if(ground)
next_state<=right_dig;
else
next_state<=right_ground;
endcase
end
always@(posedge clk or posedge areset)
if(areset)
state<=left;
else
state<=next_state;
assign walk_left = (state == left);
assign walk_right = (state == right);
assign aaah = ((state == left_ground) || (state == right_ground));
assign digging = ((state == left_dig) || (state == right_dig));
endmodule