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

含有无关项的序列检测

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

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
    parameter S0 = 4'd0;
    parameter S1 = 4'd1;
    parameter S2 = 4'd2;
    parameter S3 = 4'd3;
    parameter S4 = 4'd4;
    parameter S5 = 4'd5;
    parameter S6 = 4'd6;
    parameter S7 = 4'd7;
    parameter S8 = 4'd8;
    parameter S9 = 4'd9;
    reg [3:0] cstate, nstate;
    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            cstate <= S0;
        end
        else begin
            cstate <= nstate;
        end
    end
    always@(*) begin
        case(cstate)
            S0: nstate = a?S0:S1;
            S1: nstate = a?S2:S1;
            S2: nstate = a?S3:S1;
            S3: nstate = S4;
            S4: nstate = S5;
            S5: nstate = S6;
            S6: nstate = a?S7:S1;
            S7: nstate = a?S8:S1;
            S8: nstate = a?S0:S9;
            S9: nstate = a?S0:S1;
            default: nstate = S0;
        endcase
    end
    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            match <= 1'b0;
        end
        else begin
            match <= (cstate==S9);
        end
    end
endmodule

全部评论

相关推荐

风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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