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

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

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 [7:0]d
);
wire [7:0] m,n;

sub_mod sub1(
	.clk(clk),
	.rst_n(rst_n),
	.a(a),
	.b(b),
	.c(m)
	);

sub_mod sub2(
	.clk(clk),
	.rst_n(rst_n),
	.a(b),
	.b(c),
	.c(n)
	);

sub_mod sub3(
	.clk(clk),
	.rst_n(rst_n),
	.a(m),
	.b(n),
	.c(d)
	);

endmodule


module sub_mod(
	input clk,
	input rst_n,
	input [7:0]a,
	input [7:0]b,

	output reg [7:0]c
);

always@(posedge clk or negedge rst_n)
begin
	if(~rst_n)
		c <= 8'b0;
	else
		c <= (a < b)? a:b;
end

endmodule

全部评论

相关推荐

10-29 18:20
济南大学 Java
用微笑面对困难:他不是人事吗,怎么净特么不干人事
点赞 评论 收藏
分享
双尔:你就写拥有ai开发经历,熟练运用提示词,优化ai,提高ai回答质量
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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