adder1
You are given a module 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 module performs 16-bit a + b + cin, while your module performs 32-bit a + b). add16add16 Connect the modules together as shown in the diagram below. The provided module has the following declaration: add16 module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
Module add - HDLBits (01xz.net)
1 module top_module( 2 input [31:0] a, 3 input [31:0] b, 4 output [31:0] sum 5 ); 6 wire cout1,cout2; //声明模块内部线 7 add16 add_low16( 8 .a(a[15:0]), //定义16位,都是类似于将实参赋予形参 9 .b(b[15:0]), 10 .cin(1'b0), 11 .sum(sum[15:0]), 12 .cout(cout1) 13 ); 14 add16 add_up16( 15 .a(a[31:16]), 16 .b(b[31:16]), 17 .cin(cout1), 18 .sum(sum[31:16]), //按照图标所示,不需要将两个sum再进行综合吗,用一个拼接语法吗? 19 .cout(cout2) 20 ); 21 22 endmodule
再写:
针对注释“
//按照图标所示,不需要将两个sum再进行综合吗,用一个拼接语法吗?
”,是不用再写的,因为并行运行,直接两个分别对sum的高16、低16位同时赋值了,没有必要再拼接

浙公网安备 33010602011771号