module top_module (
input clk,
input areset,
input x,
output z
);
parameter [1:0] a=4'd0, b=4'd1, c=4'd2;
reg [1:0] state, next_state;
always @(*) begin
case(state) // State transition logic
a:begin
if( x == 1'b1 )
next_state = b;
else
next_state = a;
end
b:begin
if( x== 1'b1 )
next_state = c;
else
next_state = b;
end
c:begin
if( x == 1'b1 )
next_state = c;
else
next_state = b;
end
endcase
end
always @(posedge clk or posedge areset) begin
if(areset)
state <= a;
else
state <= next_state;// State flip-flops with asynchronous reset
end
assign z=(next_state==b) ;
endmodule
Exams/ece241 2014 q5b
最新推荐文章于 2024-06-26 15:16:03 发布