HDLBits-Verilog learning record | Verilog Language-Modules (2)

25.Adder 1 | Module add

practice:
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). You
get a module add16 that performs 16-bit addition. Instantiate two of them to create 32-bit adders. One add16 module computes the low-order 16 bits of the addition result, while the second add16 module computes the high-order 16 bits of the result after receiving the carryover from the first adder. Your 32-bit adder doesn't need to handle incoming (assumed to be 0) or outgoing (ignored), but the internal module does to function properly. (In other words, the add16 module does 16-bit a + b + cin, while the add16 module does 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 );
Insert image description here

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire cout_1;
    add16 ins_add1 ( .a(a[15:0]), .b(b[15:0]), .cin(1'b0), .sum(sum[15:0]), .cout(cout_1) );
    add16 ins_add2 ( .a(a[31:16]), .b(b[31:16]), .cin(cout_1), .sum(sum[31:16]), .cout() );

endmodule

Note: (60% of the independent completion part) Due to a misunderstanding of the question, this question is actually a matching question, but I thought it was complicated and thought it needed to be calculated or something, but the result was that the compilation failed. It seems that I haven't kept up with the basic courses here, resulting in unclear understanding of the questions.
If you don’t write .cout() in the second line, it will be a success!

26.Adder 2 | Module fadd

practice:
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.
In this exercise, you create a circuit with two hierarchy levels. Your top_module will instantiate two copies of add16 (provided), each of which will instantiate 16 copies of add1 (which you must write). Therefore, 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).
Like module_add, you get a module add16 that performs 16-bit addition. Two of them must be instantiated to create a 32-bit adder. One add16 module computes the low-order 16 bits of the addition result, while the second add16 module computes the high-order 16 bits of the result. Your 32-bit adder doesn't need to handle entries (assumed to be 0) or rollovers (ignored).

Connect the add16 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 );


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: module add1, not provided) to actually perform the addition. You must write a complete adder module with 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.
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 a module add1 , you will get an error message that says Error (12006): Node instance “user_fadd[0].a1” instantiates undefined entity “add1”. Error message stating Error (12006): Node instance 'user_fadd[0].a1' instantiates undefined entity 'add1'.
Insert image description here
Full adder equations:
sum = a ^ b ^ cin
cout = a&b | a&cin | b&cin

在这里插入代码片

27.Carry-select adder

28.Adder-subtractor

Guess you like

Origin blog.csdn.net/qq_43374681/article/details/132471453