题解 | #输入序列连续的序列检测#
输入序列连续的序列检测
https://www.nowcoder.com/practice/d65c2204fae944d2a6d9a3b32aa37b39
`timescale 1ns/1ns
module sequence_detect(
input clk,
input rst_n,
input a,
output reg match
);
//序列缓存对比法,则是将八个时刻的数据缓存,作为一个数组,每个时刻的输入位于数组的末尾,数组其它元素左移,把最早输入的数据移出。然后将数组和目标序列对比,如果数组和目标序列相等,则说明出现目标序列。
reg [7:0] b;
always@(posedge clk or negedge rst_n) begin
if(rst_n==1'b0)
b<= 8'b0;
else
b<= {b[6:0],a} ;
end
always@(posedge clk or negedge rst_n) begin
if(rst_n==1'b0)begin
match<= 1'b0;
end
else if(b==8'b01110001)begin
match<= 1'b1;
end
else begin
match<= 1'b0;
end
end
endmodule
查看11道真题和解析
九号公司成长空间 1人发布