题解 | #输入序列连续的序列检测#

输入序列连续的序列检测

http://www.nowcoder.com/practice/d65c2204fae944d2a6d9a3b32aa37b39

`timescale 1ns/1ns module sequence_detect( input clk, input rst_n, input a, output reg match ); reg [3:0] curr_state; reg [3:0] next_state; always @ (posedge clk, negedge rst_n)begin if (~rst_n)begin curr_state<=4'd0; end else begin curr_state<=next_state; end end

always @ (*)begin
    case(curr_state)
        4'd0:next_state=(a==1'b1)?4'd0:4'd1;
        4'd1:next_state=(a==1'b1)?4'd2:4'd0;
        4'd2:next_state=(a==1'b1)?4'd3:4'd0;
        4'd3:next_state=(a==1'b1)?4'd4:4'd0;
        4'd4:next_state=(a==1'b1)?4'd1:4'd5;
        4'd5:next_state=(a==1'b1)?4'd1:4'd6;
        4'd6:next_state=(a==1'b1)?4'd1:4'd7;
        4'd7:next_state=(a==1'b1)?4'd8:4'd0;            
        4'd8:next_state=(a==1'b1)?4'd0:4'd1; 
        default:next_state=4'd0;
    endcase
end

always @ (posedge clk, negedge rst_n)begin if (~rst_n)begin match<=1'b0; end else begin match<=(curr_state==4'd8); end end

endmodule

全部评论

相关推荐

我看看你怎么个事来
牛牛爱吃草草:我看看你怎么个事来
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:35
虽然不怎么光彩,经过这件事,可能我真的要去认同“面试八股文早该淘汰!不会用AI作弊的程序员=新时代文盲!”这句话了
HellowordX:Ai的出现是解放劳动力的,不是用来破坏公平竞争环境的,这样下去,轻则取消所有线上面试,严重了会影响整个行业对所有人产生影响,企业会拉高入职考核各种离谱考核会层出不穷
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务