Adder 1:module_add
You 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).
您将获得一个执行 16 位加法的模块 add16。实例化其中两个以创建一个 32 位加法器。一个 add16 模块计算加法结果的低 16 位,而第二个 add16 模块在接收到第一个加法器的进位后计算结果的高 16 位。您的 32 位加法器不需要处理进位(假设为 0)或进位(忽略),但内部模块需要才能正常工作。(换句话说,add16 模块执行 16 位 a + b + cin,而您的模块执行 32 位 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 具有以下声明:
图片 戳链接了解更多
Module Declaration
module top_module( input [31:0] a, input [31:0] b, output [31:0] sum );
module top_module(
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire cout1;
add16 add1(a[15:0],b[15:0],1'b0,sum[15:0],cout1);
add16 add2(a[31:16],b[31:16],cout1,sum[31:16],);
endmodule
Adder 2:Module fadd
In this exercise, you will create a circuit with two levels of hierarchy. Your top_module
will instantiate two copies of add16
(provided), each of which will instantiate 16 copies of add1
(which you must write). Thus, you must write two modules: top_module
and add1
.
Like module_add, you are given a module add16
that performs a 16-bit addition. You must 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. Your 32-bit adder does not need to handle carry-in (assume 0) or carry-out (ignored).
在本练习中,您将创建具有两个层次结构的电路。您的 top_module 将实例化 add16 的两个副本(已提供),每个副本将实例化 add1 的 16 个副本(您必须编写)。因此,您必须编写两个模块:top_module 和 add1。与 module_add 一样,您将获得一个执行 16 位加法的模块 add16。您必须实例化其中的两个以创建 32 位加法器。一个 add16 模块计算加法结果的低 16 位,而第二个 add16 模块计算结果的高 16 位。您的 32 位加法器不需要处理进位(假设为 0)或进位(忽略)。
Connect the add16
modules together as shown in the diagram below. The provided module add16
has the following declaration:
如下图所示将 add16 模块连接在一起。提供的模块 add16 具有以下声明:
module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
Within each add16
, 16 full adders (module add1
, not provided) are instantiated to actually perform the addition. You must write the full adder module that has the following declaration:
在每个 add16 中,实例化了 16 个全加器(模块 add1,未提供)以实际执行加法。您必须编写具有以下声明的完整加法器模块:
module add1 ( input a, input b, input cin, output sum, output cout );
Recall that a full adder computes the sum and carry-out of a+b+cin.
In summary, there are three modules in this design:
top_module
— Your top-level module that contains two of...add16
, provided — A 16-bit adder module that is composed of 16 of...add1
— A 1-bit full adder module.
回想一下,全加器计算 a+b+cin 的和和进位。综上所述,本设计共有三个模块:top_module — 您的顶级模块,其中包含两个...
add16, provided — 一个 16 位加法器模块,由 16 个...
add1 — 1 位全加器模块。
Module Declaration
module top_module ( input [31:0] a, input [31:0] b, output [31:0] sum );
Full adder equations:
sum = a ^ b ^ cin
cout = a&b | a&cin | b&cin
module top_module (
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire carry;
add16 a1(a[15:0],b[15:0],1'b0,sum[15:0],carry);
add16 a2(a[31:16],b[31:16],carry,sum[31:16],);
endmodule
module add1 ( input a, input b, input cin, output sum, output cout );
assign sum = a ^ b ^ cin;
assign cout = a&b | a&cin | b&cin;
// Full adder module here
endmodule