题解 | #使用子模块实现三输入数的大小比较#

使用子模块实现三输入数的大小比较

https://www.nowcoder.com/practice/bfc9e2f37fe84c678f6fd04dbce0ad27

`timescale 1ns/1ns
module main_mod(
	input clk,
	input rst_n,
	input [7:0]a,
	input [7:0]b,
	input [7:0]c,
	
	output 	wire	[7:0]	d
);

wire	[7:0]	x;
reg		[7:0]	y;

always @(posedge clk)
	y <= c;		//y打一拍

sub_mod m1
(
	.clk	(clk	),
	.rst_n	(rst_n	),
	.a		(a		),
	.b		(b		),
	
	.c		(x		)
);

sub_mod m2
(
	.clk	(clk	),
	.rst_n	(rst_n	),
	.a		(x		),
	.b		(y		),
	
	.c		(d		)
);


endmodule

module sub_mod(
	input clk,
	input rst_n,
	input [7:0]a,
	input [7:0]b,
	
	output 	reg		[7:0]c
);

wire	[7:0]	c_net;

assign	c_net = (a < b) ? a : b;

always@(posedge clk or negedge rst_n)
	if(!rst_n)
		c <= 8'b0;
	else
		c <= c_net;

endmodule

全部评论

相关推荐

牛客吹哨人:哨哥晚点统一更新到黑名单:能救一个是一个!26届毁意向毁约裁员黑名单https://www.nowcoder.com/discuss/1525833
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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