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

不重叠序列检测

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 integer cnt;
	reg [5:0]comp;
	always @(posedge clk or negedge rst_n)begin
		if(~rst_n)begin
			cnt<=0;
			match<=0;
			not_match<=0;
		end
			else if(cnt==5)begin
			cnt<=0;
			end
			else cnt<=cnt+1;
		end
	always @(posedge clk or negedge rst_n)begin
		if(~rst_n)begin
			comp<=6'b0;
		end
		else comp[cnt]<=data;
	end

	always@(posedge clk or negedge rst_n)begin
		match<=((comp==6'b001110)&(cnt==5))?1:0;
		not_match<=(~(comp==6'b001110)&(cnt==5))?1:0;
	end
	
endmodule

全部评论

相关推荐

头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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