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

不重叠序列检测

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

全部评论

相关推荐

2025-12-30 16:42
同济大学 C++
仁狂躁使者:哎呀,不用担心,我当时配环境配了两天,项目捋不清就问问导师能不能用ai,慢慢就清了,会好起来的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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