题解 | #含有无关项的序列检测#
含有无关项的序列检测
https://www.nowcoder.com/practice/cba67d06d6834a5d9b93e1087b56c8d8
暴力求解,序列检测器要求检测几位,那就把那几位的值给保留下来。
注意题目还有一个坑:011XXX110的最后一位0不是刚进来的a,这个坑写代码时看时序应该能分析出来。
`timescale 1ns/1ns module sequence_detect( input clk, input rst_n, input a, output reg match ); reg a1,a2,a3,a4,a5,a6,a7,a8,a9; always @(posedge clk or negedge rst_n) begin if (!rst_n)begin match<=1'b0; a2<=1'b0;a3<=1'b0;a4<=1'b0;a5<=1'b0;a6<=1'b0;a7<=1'b0;a8<=1'b0; a9<=1'b0;a1<=1'b0; end else begin if ((!a1)&a2&a3&a7&a8&(!a9))match<=1; else match<=1'b0; a9<=a8; a8<=a7; a7<=a6; a6<=a5; a5<=a4; a4<=a3; a3<=a2; a2<=a1; a1<=a; end end endmodule