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

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

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 15:39
希望奇迹发生的布莱克...:真的是 现在卷实习就是没苦硬吃
点赞 评论 收藏
分享
Gaynes:查看图片
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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