题解 | #输入序列连续的序列检测#
输入序列连续的序列检测
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]data;
always@(posedge clk or negedge rst_n)
if (rst_n == 1'b0)
data <= 8'b0;
else
data <= (data << 1) + a;
always@(posedge clk or negedge rst_n)
if (rst_n == 1'b0)
match <= 1'b0;
else if (data[0] == 1'b1 && data[1] == 1'b0 && data[2] == 1'b0 && data[3] == 1'b0 && data[4] == 1'b1 && data[5] == 1'b1 && data[6] == 1'b1 && data[7] == 1'b0)
match <= 1'b1;
else
match <= 1'b0;
endmodule
在这里使用移位的方法完成对输入数据的接收和寄存。
查看3道真题和解析

