본문 바로가기

Verilog/HDLbits

[HDLBits] Module fadd

1. 문제 및 설명

  • 모듈의 계층 구조는 한 모듈안에서 다른 모듈을 인스턴스화 함으로써 만들어집니다.
  • <module add16 ( input [15:0] a, input [15:0] b, input cin, output [15:0] sum, output cout);> 이 제공될 때 이 모듈을 두 번 인스턴스화 하여 아래 모듈을 설계하세요. 
  • add16은 add1 모듈 16개를 인스턴스화 하며, add1 모듈을 설계해야 합니다.

2. 모듈 정의

module top_module (
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);

 

 

 

3. 답

module top_module (
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);//
    wire cout, trash;
    add16 i0 ( a[15:0], b[15:0], 1'b0, sum[15:0], cout);
    add16 i1 ( a[31:16], b[31:16], cout, sum[31:16], trash);

endmodule

module add1 ( input a, input b, input cin,   output sum, output cout );

// Full adder module here
    assign sum = a^b^cin;
    assign cout = a*b + b*cin + a*cin;

endmodule

'Verilog > HDLbits' 카테고리의 다른 글

[HDLBits] Module addsub  (0) 2025.11.18
[HDLBits] Module cseladd  (0) 2025.11.18
[HDLBits] Module add  (0) 2025.11.02
[HDLBits] Module shift8  (0) 2025.11.02
[HDLBits] Module shift  (0) 2025.11.02