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

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

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] u,v;

test u1(
	.clk(clk),
	.rst_n(rst_n),
	.a(a),
	.b(b),
	.d(u)
);

test u2(
	.clk(clk),
	.rst_n(rst_n),
	.a(a),
	.b(c),
	.d(v)
);

test u3(
	.clk(clk),
	.rst_n(rst_n),
	.a(u),
	.b(v),
	.d(d)
);
endmodule

module test(
	input clk,
	input rst_n,
	input [7:0]a,
	input [7:0]b,
	output [7:0]d
);
reg [7:0] d;
	always@(posedge clk or negedge rst_n)begin
		if(!rst_n)
			d <= 8'd0;
		else if(a>b)
			d<= b;
		else 
			d <= a;
	end
	
endmodule

全部评论

相关推荐

03-04 19:02
云南大学 Java
Yki_:没挂,只是没人捞,该干啥干啥,等着就好了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务