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

不重叠序列检测

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
	);
	// cnt
	reg [2:0] cnt;
	always @(posedge clk, negedge rst_n) begin
		if(!rst_n) begin
			cnt <= 0;
		end
		else begin
			cnt <= (cnt == 5)? 0 : cnt + 1;
		end
	end

	// data shift
	reg [5:0] data_r;
	always @(posedge clk, negedge rst_n) begin
		if(!rst_n) begin
			data_r <= 0;
		end
		else begin
			data_r <= {data_r[4:0], data};
		end
	end

	// match
	always @(posedge clk, negedge rst_n) begin
		if(!rst_n) begin
			match <= 0;
			not_match <= 0;
		end
		else if(cnt == 5) begin
			match     <= ({data_r[4:0], data} == 6'b011100);
			not_match <= !match;//({data_r[4:0], data} != 6'b011100);
		end
		else begin
			match <= 0;
			not_match <= 0;
		end
	end

endmodule

第三段的 not_match <= !match 结果错误,这是为什么呢?

#悬赏#
全部评论

相关推荐

点赞 评论 收藏
分享
风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
07-07 12:47
门头沟学院 Java
码农索隆:竟然还真有卡体检报告的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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