1、题目See also: Lemmings1.In addition to walking left and right, Lemmings will fall (and presumably go aaah!) if the ground disappears underneath them.In addition to walking left and right and changing direction when bumped, when ground0, the Lemming will fall and say aaah!. When the ground reappears (ground1), the Lemming will resume walking in the same direction as before the fall. Being bumped while falling does not affect the walking direction, and being bumped in the same cycle as ground disappears (but not yet falling), or when the ground reappears while still falling, also does not affect the walking direction.Build a finite state machine that models this behaviour.See also: Lemmings3 and Lemmings4.2、分析旅鼠游戏2旅鼠可以左右行走如果地面消失于脚下它们会摔跤并发出“啊啊啊”的声音如果地面重新出现它们就以之前的方向继续前进。注意掉落前的状态为左还是左如此看来可知有四种情况向左向右掉落前向左掉落前向右。3、代码module top_module( input clk, input areset, // Freshly brainwashed Lemmings walk left. input bump_left, input bump_right, input ground, output walk_left, output walk_right, output reg aaah ); parameter LEFT2b00,RIGHT2b01,fall_left2b10,fall_right2b11; reg [1:0]state,next_state; always(*)begin next_state state; case(state) LEFT:begin if(!ground) next_statefall_left; else begin if(bump_left) next_stateRIGHT; else next_stateLEFT; end end RIGHT:begin if(!ground) next_statefall_right; else begin if(bump_right) next_stateLEFT; else next_stateRIGHT; end end fall_left:begin if(ground) next_stateLEFT; else next_statefall_left; end fall_right:begin if(ground) next_stateRIGHT; else next_statefall_right; end default:next_stateLEFT; endcase end always(posedge clk,posedge areset)begin if(areset) stateLEFT; else statenext_state; end always(posedge clk,posedge areset)begin if(areset) aaah1b0; else if(ground1b0) aaah1b1; else aaah1b0; end assign walk_left(stateLEFT); assign walk_right(stateRIGHT); endmodule4、结果