题解 | #不重叠序列检测#

不重叠序列检测

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

`timescale 1ns/1ns
module sequence_detect(
    input clk,
    input rst_n,
    input data,
    output wire match,
    output wire not_match
);

//--- shift register of data
reg [6:0] reg_data;
always @(posedge clk or negedge rst_n) begin
    if(~rst_n)
        reg_data <= 7'b000_0001;
    else if(reg_data[6] == 1'b1)
        reg_data <= {6'b00_0001,data};
    else
        reg_data <= {reg_data[5:0],data};
end

//--- output match
assign match = ((reg_data[6] == 1'b1) & (reg_data[5:0] == 6'b011100)) ? 1 : 0;
//--- output not match
assign not_match = ((reg_data[6] == 1'b1) & (reg_data[5:0] != 6'b011100)) ? 1 : 0;
endmodule

@牛客503184514号 网友的解法,很简洁(不过,修改了输出port的类型 reg->wire,看来系统不检测这个,只有输入输出port数量和位数对就OK :) )

另,有个笔误: else if(reg_data[7] == 1'b1) -----> else if(reg_data[6] == 1'b1)

~~ ~~

全部评论

相关推荐

哞客37422655...:这就是真实社会,没有花里胡哨的安慰,让你感受到阶级分明,不浪费彼此时间。虽然露骨但是唉
点赞 评论 收藏
分享
程序员小白条:三方不签,不就是纯实习骗人吗,还是小公司,没毛了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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