HBLbits_Verilog Basic_Module cseladd
module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
module top_module(
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire cin0,cin1,cout,cout1,cout2;
wire [15:0]sum1,sum2;
assign cin0=1'b0;
assign cin1=1'b1;
//add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
add16 u0 ( a[15:0], b[15:0], cin0, sum[15:0],cout );
add16 u1 ( a[31:16], b[31:16], cin0, sum1[15:0],cout1 );
add16 u2 ( a[31:16], b[31:16], cin1, sum2[15:0],cout2 );
always @(*)
case (cout)
1'b0: sum[31:16]=sum1[15:0];
1'b1: sum[31:16]=sum2[15:0];
endcase
endmodule
input [31:0] b,
output [31:0] sum
);
wire cin0,cin1,cout,cout1,cout2;
wire [15:0]sum1,sum2;
assign cin0=1'b0;
assign cin1=1'b1;
//add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
add16 u0 ( a[15:0], b[15:0], cin0, sum[15:0],cout );
add16 u1 ( a[31:16], b[31:16], cin0, sum1[15:0],cout1 );
add16 u2 ( a[31:16], b[31:16], cin1, sum2[15:0],cout2 );
always @(*)
case (cout)
1'b0: sum[31:16]=sum1[15:0];
1'b1: sum[31:16]=sum2[15:0];
endcase
endmodule
沒有留言:
張貼留言