题解 | #使用子模块实现三输入数的大小比较#
使用子模块实现三输入数的大小比较
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 ); // reg [7:0] d ; wire [7:0] min_mid ; reg [7:0] c_temp; always@(posedge clk or negedge rst_n)begin if(!rst_n)begin c_temp <= 8'b0; end else begin c_temp <= c; end end son_mod u1( .clk(clk), .rst_n(rst_n), .a(a), .b(b), .min(min_mid) ); son_mod u2( .clk(clk), .rst_n(rst_n), .a(min_mid), .b(c_temp), .min(d) ); endmodule module son_mod( input clk, input rst_n, input [7:0]a, input [7:0]b, output reg [7:0]min ); // reg [7:0] c; always@(posedge clk or negedge rst_n)begin if(!rst_n)begin min <= 8'b0; end else begin if (a > b) min <= b; else min <= a; end end endmodule
1.延迟c一个周期,因为第一个比较需要消耗一个周期;
2.在initial中使用repeat会有空块的提示,暂未找到解决办法,以后在task中使用;
3.tb中,保证输入数据的变化不发生在时钟下降沿