题解 | #使用子模块实现三输入数的大小比较#
使用子模块实现三输入数的大小比较
https://www.nowcoder.com/practice/bfc9e2f37fe84c678f6fd04dbce0ad27
`timescale 1ns/1ns // 输入两个8bit位宽的变量data_a,data_b,并输出data_a,data_b之中较小的数。并在主模块中例化,实现输出三个8bit输入信号的最小值的功能。 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]tmp0,tmp1; sub_mod sub_mod0(.clk(clk), .rst_n(rst_n), .a(a), .b(b), .c(tmp0)); sub_mod sub_mod1(.clk(clk), .rst_n(rst_n), .a(a), .b(c), .c(tmp1)); sub_mod sub_mod2(.clk(clk), .rst_n(rst_n), .a(tmp0), .b(tmp1), .c(d)); endmodule module sub_mod(input clk,input rst_n,input [7:0]a,input [7:0]b,output [7:0]c); reg [7:0]c_tmp; always@ (posedge clk or negedge rst_n) begin if(!rst_n) c_tmp<=8'b0; else c_tmp<=a<b?a:b; end assign c=c_tmp; endmodule