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

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

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]temp1;
	wire [7:0]temp2;
	compare com1(
		.clk(clk),
		.rst_n(rst_n),
		.a(a),
		.b(b),
		.out(temp1)
	);
		compare com2(
		.clk(clk),
		.rst_n(rst_n),
		.a(a),
		.b(c),
		.out(temp2)
	);
		compare com3(
		.clk(clk),
		.rst_n(rst_n),
		.a(temp1),
		.b(temp2),
		.out(d)
	);
endmodule

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

	output [7:0]out
);
   reg[7:0]com;
   always@(posedge clk or negedge rst_n)
   if(!rst_n)
   com<=0;
   else begin
	com<=(a>=b)?b:a;
   end
   assign out=com;
endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-21 13:38
8月实习会变多吗现在还没找到实习该怎么办...回复的hr好少
码农索隆:3-4月就要开始找,基本上6月份就发offer,7月初已经开始暑期实习了。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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