In this exercise, you will create a circuit with two levels of hierarchy. Your
top_module
will instantiate two copies ofadd16
(provided), each of which will instantiate 16 copies ofadd1
(which you must write). Thus, you must write two modules:top_module
andadd1
.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. Oneadd16
module computes the lower 16 bits of the addition result, while the secondadd16
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).Connect the
add16
modules together as shown in the diagram below. The provided moduleadd16
has the following declaration:
module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
Within each
add16
, 16 full adders (moduleadd1
, not provided) are instantiated to actually perform the addition. You must write the full adder module that has the following declaration:
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.
If your submission is missing amodule add1
, you will get an error message that saysError (12006): Node instance "user_fadd[0].a1" instantiates undefined entity "add1"
.
今天的题目好长,大意就是说本次练习,我要创建一个带有两层的电路,顶层电路是由2个16位加法器组成,每个16位加法器是由16个1位加法器组成,所以题目说我必须写2个模块,一个是顶层模块,另一个是1位加法器。就像上一道题一样你用给出的16位加法器做16位加法,这中间你必须实例化2个16位加法器才能创造出一个32位加法器,其中……(这个端和上题一样,此处省略不写)。最后你的32位加法器不需要处理进位数据。
之后题目又说像图中那样子连接16位加法器,16位加法器被提供在下面中,在这个16位加法器中有16个并未提供的全加器在运行,我必须写出全加器的模块,就利用下面的格式。
之后题目给了点提示,回忆一下全加器计算a+b+cin的和和进位。当然最后如果你忘记写全加器了,也没事,最终的运行结果会告诉你,你有一个错误,是12006。
上图,把题目的图片放在这里
下面就是我写的程序
module top_module (
input [31:0] a,
input [31:0] b,
output [31:0] sum
);//
add16 add16_1(
.a(a[15:0]),
.b(b[15:0]),
.sum(sum[15:0]),
.cin(1'b0),
.cout(c)
);
add16 add16_2(
.a(a[31:16]),
.b(b[31:16]),
.sum(sum[31:16]),
.cin(c)
);
wire c;
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);
endmodule