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

输入序列连续的序列检测

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

`timescale 1ns/1ns module sequence_detect( input clk, input rst_n, input a, output reg match ); localparam idle =9'b000000000; localparam s1 =9'b000000001; localparam s2 = 9'b000000010; localparam s3 = 9'b000000100; localparam s4 = 9'b000001000;

localparam s5 = 9'b000100000;
localparam s6 = 9'b001000000;
localparam s7 = 9'b010000000;
localparam s8 = 9'b100000000;
reg [8:0] cs,ns;

always@(posedge clk or negedge rst_n) begin
    if(!rst_n) 
        cs <= 8'b0;
    else cs <= ns;
end

always@(*) begin
    case(cs)
        idle:begin
            if(a==0) ns = s1;
            else ns = idle;
        end
        s1:begin
            if(a==0) ns = s1;
            else ns = s2;
        end
        s2:begin
            if(a==0) ns = s1;
            else ns = s3;
        end
        s3:begin
            if(a==0) ns = s1;
            else ns = s4;
        end
        s4:begin
            if(a==0) ns = s5;
            else ns = idle;
        end
        s5:begin
            if(a==0) ns = s6;
            else ns = s2;
        end
        s6:begin
            if(a==0) ns = s7;
            else ns = s2;
        end
        s7:begin
            if(a==0) ns = s1;
            else ns = s8;
        end
        s8:begin
            if(a==0) ns = s1;
            else ns = s3;
        end
        default: ns = idle;
    endcase
end

always@(posedge clk or negedge rst_n) begin
    if(!rst_n) 
        match <= 0;
    else if(cs == s8)  match <= 1;
    else  match <= 0;

end

endmodule

全部评论

相关推荐

吐泡泡的咸鱼:我也工作了几年了,也陆陆续续面试过不少人,就简历来说,第一眼学历不太够,你只能靠你的实习或者论文或者项目经历,然后你没有论文,没有含金量高的比赛和奖项,只能看实习和项目,实习来说,你写的实习经历完全不清楚你想找什么工作?行研?数据分析?且写的太少了,再看项目,这些项目先不说上过大学读过研究生的都知道很水,然后对你想找的岗位有什么帮助呢?项目和实习也完全不匹配啊,你好像在努力将你所有的经历都放在简历里想表现你的优秀,但是对于你想找的岗位来说,有什么用呢?最后只能获得岗位不匹配的评价。所以你需要明白你想要找的岗位要求是什么,是做什么的,比如产品经理,然后再看你的经历里有什么匹配的上这个岗位,或者对这个岗位以及这个岗位所在的公司有价值,再写到你的简历上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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