题解 | #含有无关项的序列检测#

含有无关项的序列检测

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

````timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
    //first way
   reg [9:0] state;
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n)  state <= 9'b0;
        else state <= {state[7:0], a};
    end
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n) match <= 0;
        else 
           /* casez(state)
             9'b011zzz110: match <= 1;
             default: match <= 0;
        endcase*/
            if(state[8:6]==3'b011 && state[2:0]==3'b110) match <= 1;
            else match <= 0;
    end
    //second way
    /*localparam IDLE=0, S0=1, S01=2, S011=3, B1=4, B2=5, B3=6, SB1=7, SB11=8, SB110=9;
    reg [3:0] state, next_state;
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n) state <= IDLE;
        else state <= next_state;
    end
    always@(*)begin
        case(state)
            IDLE:next_state = a? IDLE:S0;
            S0:  next_state = a? S01:S0;
            S01: next_state = a? S011:S0;
            S011:next_state = B1;
            B1:  next_state = B2;
            B2:  next_state = B3;
            B3:  next_state = a? SB1:S0;
            SB1: next_state = a? SB11:S0;
            SB11:next_state = a? IDLE:SB110;
            SB110:next_state = a? S01:S0;
        endcase
    end
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n) match <= 0;
        else if(state == SB110) match <= 1;
        else match <= 0;
    end*/
endmodule
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 16:22
点赞 评论 收藏
分享
06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
代码飞升:别用口语,后端就写后端,前端就写前端,最后别光后悔
点赞 评论 收藏
分享
这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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