题解 | #不重叠序列检测#
不重叠序列检测
https://www.nowcoder.com/practice/9f91a38c74164f8dbdc5f953edcc49cc
`timescale 1ns/1ns module sequence_detect( input clk, input rst_n, input data, output reg match, output reg not_match ); reg [2:0]cnt; always@(posedge clk or negedge rst_n) if (rst_n == 1'b0) cnt <= 3'b0; else if (cnt == 3'd5) cnt <= 3'b0; else cnt <= cnt + 1'b1; reg [5:0]data_reg; always@(posedge clk or negedge rst_n) case(cnt) 3'd0 : data_reg[0] <= data; 3'd1 : data_reg[1] <= data; 3'd2 : data_reg[2] <= data; 3'd3 : data_reg[3] <= data; 3'd4 : data_reg[4] <= data; 3'd5 : data_reg[5] <= data; default : data_reg <= 6'b0; endcase always@(posedge clk or negedge rst_n) if (rst_n == 1'b0) begin match <= 1'b0; not_match <= 1'b0; end else if (cnt == 3'd5) begin if (data_reg == 6'b00_1110) begin match <= 1'b1; not_match <= 1'b0; end else begin match <= 1'b0; not_match <= 1'b1; end end else begin match <= 1'b0; not_match <= 1'b0; end endmodule
为什么我自测运行显示“您的程序未能在规定时间内运行结束,请检查是否循环有错或算法复杂度过大。”,但是提交后可以通过???