题解 | 不重叠序列检测

不重叠序列检测

https://www.nowcoder.com/practice/9f91a38c74164f8dbdc5f953edcc49cc

//不重叠序列检测,舍去之前结果
`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,
	output reg match, // Match output
    output reg not_match // Not match output
	);

    reg [5:0] reg_a;
    reg [2:0] cnt;
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            reg_a <= 'b0; // Reset the register
            cnt <= 3'b0; // Reset the counter
        end else begin
            reg_a <= {reg_a[5:0], data}; // Shift in the new bit 'a'
            if (cnt < 3'd6) begin
                cnt <= cnt + 1; // Increment the counter until it reaches 7
            end else begin
                cnt <= 3'b1; // Keep the counter at 7 after reaching it
            end
        end
    end

always @(*) begin
        if (!rst_n) begin
            match <= 1'b0;
            not_match <= 1'b0; // Initialize not_match flag
        end else if(reg_a == 6'b011100 && cnt == 'd6)begin      //左边高位,右边低位
            match <= 1'b1; // Match found for the sequence "011xxx001"
            not_match <= 1'b0; // Reset not_match flag
        end else if(reg_a != 6'b011100 && cnt == 'd6)begin
            match <= 1'b0; // No match
            not_match <= 1'b1; // Set not_match flag
        end else begin
            match <= 1'b0; // No match
            not_match <= 1'b0; // Set not_match flag
        end
    end

endmodule

全部评论

相关推荐

程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
秋招吐槽大会
点赞 评论 收藏
分享
12-19 16:52
门头沟学院
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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