u are given a module add16
that performs a 16-bit addition. Instantiate two of them to create a 32-bit adder. One add16 module computes the lower 16 bits of the addition result, while the second add16 module computes the upper 16 bits of the result, after receiving the carry-out from the first adder. Your 32-bit adder does not need to handle carry-in (assume 0) or carry-out (ignored), but the internal modules need to in order to function correctly. (In other words, the add16
module performs 16-bit a + b + cin, while your module performs 32-bit a + b).
Connect the modules together as shown in the diagram below. The provided module add16
has the following declaration:
module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
译:
您拥有一个名为add16的模块,该模块执行16位加法运算。您需要实例化两个这样的模块来构建一个32位加法器。其中一个add16模块负责计算加法结果的低16位,而另一个add16模块则在接收到第一个加法器的进位输出后,计算结果的高16位。您的32位加法器不需要处理进位输入(假设为0)或进位输出(将被忽略),但内部模块为了正确运作需要能够处理进位。 换句话说,add16模块执行的是16位的 a + b + cin 的加法运算,而您的模块执行的是32位的 a + b 的加法运算。
请根据下图所示连接这些模块。所提供的add16模块具有以下声明:
module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
module top_module(
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire out_in1,out_in2;
wire [15:0]sum1,sum2;
add16 add1(a[15:0],b[15:0],1'b0,sum1[15:0],out_in1);
add16 add2(a[31:16],b[31:16],out_in1,sum2[15:0],out_in2);
assign sum={sum2,sum1};
endmodule
运行结果: