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

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

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 reg [7:0]d
);
wire [7:0]      min_ab ;
reg  [7:0]      c_reg;

always @ (posedge clk or negedge rst_n) begin
	if(!rst_n)
		c_reg  <= 8'd0 ;
	else
		c_reg  <= c ; 
endS
always @ (posedge clk or negedge rst_n) begin
	if(!rst_n)
		d <= 8'd0 ;
	else
		d <= ( c_reg < min_ab ) ? c_reg : min_ab ; 
end
sub_mod inst_sub_mod(
		.data_a 		(a),
		.data_b         (b),
		.min_ab         (min_ab),
		.clk	        (clk),
		.rst_n          (rst_n)
);
endmodule

module sub_mod(
	input clk,
	input rst_n,
	input [7:0]data_a,
	input [7:0]data_b,
	
	output reg [7:0]min_ab
);

always @ (posedge clk or negedge rst_n) begin
	if(!rst_n)
		min_ab <= 8'd0 ;
	else
		min_ab <= ( data_a < data_b) ? data_a : data_b ;
end

endmodule

1.always块只能赋值一个变量,在一个块内会报错

async reset use as sync:异步重置用作同步

not synthesisable :合成

2.Verilog模块中的过程块(initial/always)、模块调用、assign赋值间是并行的

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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